Пример #1
0
        static void day9()
        {
            long[]         inputs  = getInputs("./day9/input.txt")[0].Split(',').Select(x => long.Parse(x)).ToArray();
            IntcodeMachine machine = new IntcodeMachine(inputs);

            machine.input.Enqueue(1);
            machine.runToEnd();
            machine.printOutput(); // Part 1. Answer: 2171728567

            machine = new IntcodeMachine(inputs);
            machine.input.Enqueue(2);
            machine.runToEnd();
            machine.printOutput(); // Part2. Answer: 49815
        }
Пример #2
0
        static void day5()
        {
            long[]         inputs  = getInputs("./day5/input.txt")[0].Split(',').Select(x => long.Parse(x)).ToArray();
            IntcodeMachine machine = new IntcodeMachine(inputs);

            machine.input.Enqueue(1);
            machine.runToEnd();
            machine.printOutput(); // Part 1. Answer: 7988899

            machine = new IntcodeMachine(inputs);
            machine.input.Enqueue(5);
            machine.runToEnd();
            machine.printOutput(); // Part 2. Answer: 13758663
        }
Пример #3
0
        static void day2()
        {
            long[] inputs = getInputs("./day2/input.txt")[0].Split(',').Select(x => long.Parse(x)).ToArray();

            inputs[1] = 12;
            inputs[2] = 2;
            IntcodeMachine machine = new IntcodeMachine(inputs);

            machine.runToEnd();
            Console.WriteLine($"Part 1: {machine.memory[0]}"); // Part 1. Answer: 7210630

            bool found = false;

            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    inputs[1] = i;
                    inputs[2] = j;
                    machine   = new IntcodeMachine(inputs);
                    machine.runToEnd();
                    long output = machine.memory[0];
                    if (output == 19690720)
                    {
                        Console.WriteLine("Answer found:");
                        Console.WriteLine(i + " " + j);
                        Console.WriteLine((100 * i) + j); // Part 2. Answer: 3892
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    break;
                }
            }
        }