Esempio n. 1
0
        static void Main()
        {
            string[] input = File.ReadLines("Task1.txt").First().Split(',');
            program = Array.ConvertAll(input, int.Parse);
            VM      = new IntCodeVM(program);
            int[] answer = Test();

            Console.WriteLine(String.Format("N: {0} v: {1}, Answser:{2}", answer[0], answer[1], 100 * answer[0] + answer[1]));
            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            long result   = 0;
            long maxValue = 100;

            program = FetchInput();
            long noun   = 1;
            long verb   = 1;
            long target = 19690720;

            {
                long[] prog = (long[])program.Clone();
                prog[1] = 12;
                prog[2] = 2;
                vm      = new IntCodeVM(1, prog);
                #if DEBUG
                //vm.Verbose = true;
                #endif
                vm.SpecialInstructions = "Day2";
                vm.Run();

                result = vm.Output;
            }

            Console.WriteLine("Part 1 result: {0}", result);

            while (result != target)
            {
                long[] prog = (long[])program.Clone();
                prog[1] = noun;
                prog[2] = verb;
                vm      = new IntCodeVM(1, prog);
                #if DEBUG
                //vm.Verbose = true;
                #endif
                vm.SpecialInstructions = "Day2";
                vm.Run();
                result = vm.Output;

                if (result == target)
                {
                    break;
                }

                if (verb < maxValue)
                {
                    verb++;
                }
                else if (noun < maxValue)
                {
                    noun++;
                    verb = 0;
                }
                else
                {
                    Console.WriteLine("No combination resulted in {0} with maxValue of {1}.", target, maxValue);
                }
            }

            Console.WriteLine("Part 2 values: {0}, {1}", noun, verb);
            sw.Stop();

            Console.WriteLine("Completed in {0} ms ({1} ticks).", sw.ElapsedMilliseconds, sw.ElapsedTicks);
            Console.Read();
            Environment.Exit(0);
        }