コード例 #1
0
ファイル: Program.cs プロジェクト: evanc5/advent-of-code-2019
        private static void Part1()
        {
            var sw  = System.Diagnostics.Stopwatch.StartNew();
            var ram = new long[rom.Count];

            rom.CopyTo(ram, 0);
            ram[1] = 12;
            ram[2] = 2;
            IntcodeComputer computer = new IntcodeComputer(ram);
            long            output   = computer.Run();

            System.Diagnostics.Debug.WriteLine($"Part 1: {output}");
            sw.Stop();
            System.Diagnostics.Debug.WriteLine(sw.Elapsed);
        }
コード例 #2
0
        public static int Run(IEnumerable <int> initialPositions)
        {
            var computer = new IntcodeComputer(initialPositions);

            for (var noun = 0; noun < 100; noun++)
            {
                for (var verb = 0; verb < 100; verb++)
                {
                    computer.SetInitialNounAndVerb(noun, verb);
                    computer.Run();
                    if (computer.PeekResult() == 19690720)
                    {
                        return(100 * noun + verb);
                    }
                    computer.Reset();
                }
            }

            throw new IndexOutOfRangeException("ran out of nouns and verbs to try");
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: evanc5/advent-of-code-2019
        private static void Part2()
        {
            var sw  = System.Diagnostics.Stopwatch.StartNew();
            var ram = new long[rom.Count];

            for (int i = 0; i < 99; i++)
            {
                for (int j = 0; j < 99; j++)
                {
                    rom.CopyTo(ram, 0);
                    ram[1] = i;
                    ram[2] = j;
                    IntcodeComputer computer = new IntcodeComputer(ram);
                    long            output   = computer.Run();
                    if (output == 19690720)
                    {
                        System.Diagnostics.Debug.WriteLine($"Part 2: {100 * i + j}");
                        sw.Stop();
                        System.Diagnostics.Debug.WriteLine(sw.Elapsed);
                        return;
                    }
                }
            }
        }