Example #1
0
        public static void Part2()
        {
            var program = Input.Split(',').Select(a => Convert.ToInt64(a)).ToArray();
            //var program = "3,9,8,9,10,9,4,9,99,-1,8".Split(',').Select(a => Convert.ToInt32(a)).ToArray();
            //var program = "3,9,7,9,10,9,4,9,99,-1,8".Split(',').Select(a => Convert.ToInt32(a)).ToArray();
            //var program = "3,3,1108,-1,8,3,4,3,99".Split(',').Select(a => Convert.ToInt32(a)).ToArray();
            //var program = "3,3,1107,-1,8,3,4,3,99".Split(',').Select(a => Convert.ToInt32(a)).ToArray();
            //var program = "3,12,6,12,15,1,13,14,13,4,13,99,-1,0,1,9".Split(',').Select(a => Convert.ToInt32(a)).ToArray();
            //var program = "3,3,1105,-1,9,1101,0,0,12,4,12,99,1".Split(',').Select(a => Convert.ToInt32(a)).ToArray();

            var c = new Intcode.Day5Computer();

            c.Run(program, new[] { 5L });

            while (c.OutputAvailable)
            {
                Console.WriteLine(c.GetOutput());
            }

            //foreach( var inp in new[] { -1,0,1 } ) {
            //	c.Run(program.Clone() as int[], new[] { inp });
            //	foreach( var o in c.Output )
            //		Console.WriteLine(o);
            //}
        }
Example #2
0
        public static void Part1()
        {
            var program = m_input.Split(',').Select(a => Convert.ToInt64(a)).ToArray();
            //var program = "3,15,3,16,1002,16,10,16,1,16,15,15,4,15,99,0,0".Split(',').Select(a => Convert.ToInt32(a)).ToArray();
            //var program = "3,23,3,24,1002,24,10,24,1002,23,-1,23,101,5,23,23,1,24,23,23,4,23,99,0,0".Split(',').Select(a => Convert.ToInt32(a)).ToArray();

            var cur   = long.MinValue;
            var perms = GetPermutations(new long[] { 0, 1, 2, 3, 4 }, 5);
            var comp  = new Intcode.Day5Computer();

            foreach (var perm in perms)
            {
                var inp = 0L;

                foreach (var phase in perm)
                {
                    comp.Run(program, new[] { phase, inp });
                    inp = comp.GetOutput();
                }

                if (cur < inp)
                {
                    cur = inp;
                }
            }

            Console.WriteLine(cur);
        }
Example #3
0
        public static void Part1()
        {
            var program = Input.Split(',').Select(a => Convert.ToInt64(a)).ToArray();
            //var program = "1002,4,3,4,33".Split(',').Select(a => Convert.ToInt32(a)).ToArray();

            var c = new Intcode.Day5Computer();

            c.Run(program, new[] { 1L });

            while (c.OutputAvailable)
            {
                Console.WriteLine(c.GetOutput());
            }
        }