Пример #1
0
        protected override object SolvePart1()
        {
            vm.ResetVM();
            vm.Execute(new long[] { 1 });

            return(vm.Output.Last());
        }
Пример #2
0
        protected override object SolvePart2()
        {
            var vm = new IntcodeVM(Input[0]);

            for (var noun = 0; noun < 100; noun++)
            {
                for (var verb = 0; verb < 100; verb++)
                {
                    vm.Write(1, noun);
                    vm.Write(2, verb);

                    vm.Execute();

                    if (vm.Read(0) != 19690720)
                    {
                        vm.ResetVM();
                        continue;
                    }

                    return(100 * noun + verb);
                }
            }

            return(null);
        }
Пример #3
0
        protected override object SolvePart1()
        {
            var maxOutput     = 0L;
            var phaseSettings = new long[] { 0, 1, 2, 3, 4 };
            var vm            = new IntcodeVM(Input[0]);

            do
            {
                // Amp A
                vm.ResetVM();
                var input = new[] { phaseSettings[0], 0 };
                vm.Execute(input);
                var output = vm.Output.ToArray();

                // Amp B
                vm.ResetVM();
                input = new[] { phaseSettings[1], output[0] };
                vm.Execute(input);
                output = vm.Output.ToArray();

                // Amp C
                vm.ResetVM();
                input = new[] { phaseSettings[2], output[0] };
                vm.Execute(input);
                output = vm.Output.ToArray();

                // Amp D
                vm.ResetVM();
                input = new[] { phaseSettings[3], output[0] };
                vm.Execute(input);
                output = vm.Output.ToArray();

                // Amp E
                vm.ResetVM();
                input = new[] { phaseSettings[4], output[0] };
                vm.Execute(input);
                output = vm.Output.ToArray();

                if (output[0] > maxOutput)
                {
                    maxOutput = output[0];
                }
            } while (phaseSettings.NextPermutation());

            return(maxOutput);
        }