Example #1
0
        private ResultOpcode ExecuteAmplifier(bool isLoopMode, string[] array, string amplifierName, int phase, List <Int64> input, Int64 state = 0)
        {
            ResultOpcode result        = new ResultOpcode();
            bool         isPhaseNumber = true;

            if (phase < 0)
            {
                Console.WriteLine("Define phase setting for amplifier " + amplifierName + ":");
                string phaseSettingString = Console.ReadLine();
                isPhaseNumber = int.TryParse(phaseSettingString, out phase);
            }
            if (isPhaseNumber && ((isLoopMode && (phase < 10) && (phase >= 5)) || (!isLoopMode && (phase < 5) && (phase >= 0))))
            {
                IntcodeProgram intcodeProgram = new IntcodeProgram();
                result = intcodeProgram.IntcodeExtended(array, input, state);

                if (amplifierName.Equals("E") && result.output > maximum)
                {
                    maximum = result.output;
                }
            }
            else
            {
                Console.WriteLine("Wrong phase setting value");
            }
            return(result);
        }
Example #2
0
        public void Execute()
        {
            Console.WriteLine("");
            Console.WriteLine("--- Day 9: Sensor Boost      ---");
            Console.WriteLine("---------------------------------");
            string[] array = File.ReadAllText(Directory.GetCurrentDirectory() + "\\Files\\Day9-Input.txt").Split(',');

            IntcodeProgram intcodeProgram = new IntcodeProgram();
            ResultOpcode   result         = intcodeProgram.IntcodeExtended(array, new List <Int64> {
                1
            });

            Console.WriteLine("Diagnostic code:{0}", result.output);

            string[]       array2          = File.ReadAllText(Directory.GetCurrentDirectory() + "\\Files\\Day9-Input.txt").Split(',');
            IntcodeProgram intcodeProgram2 = new IntcodeProgram();
            ResultOpcode   result2         = intcodeProgram2.IntcodeExtended(array2, new List <Int64> {
                2
            });

            Console.WriteLine("Diagnostic code:{0}", result2.output);
        }