Beispiel #1
0
        public static int Run(IEnumerable <int> initialPositions)
        {
            var computer = new IntcodeComputer(initialPositions);

            // 1202 program alarm
            computer.SetInitialNounAndVerb(12, 2);

            computer.Run();
            return(computer.PeekResult());
        }
Beispiel #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");
        }