Ejemplo n.º 1
0
        public void Process(int[] intCode)
        {
            int?   highest = null;
            string combo   = "";

            List <string>         settingsCollection = Permutations.GetPermutations("01234");
            IntCodeParserSetInput parser             = new IntCodeParserSetInput(intCode);

            foreach (string settings in settingsCollection)
            {
                List <Amplifier> amplifiers = new List <Amplifier>();

                int input = 0;
                foreach (char setting in settings)
                {
                    Queue <int> inputs = new Queue <int>();
                    inputs.Enqueue(int.Parse(setting.ToString()));
                    inputs.Enqueue(input);
                    Amplifier amp = new Amplifier(inputs);
                    parser.Cursor = 0;
                    parser.Process(amp.GetInputs());
                    input = parser.LastOutput;
                }

                if (highest == null || input > highest)
                {
                    highest = input;
                    combo   = settings;
                }
            }

            Console.WriteLine("{0} made {1}", combo, highest);
        }
Ejemplo n.º 2
0
        public void Process(int[] intCode)
        {
            int?   highest = null;
            string combo   = "";

            List <string> settingsCollection = Permutations.GetPermutations("56789");

            foreach (string settings in settingsCollection)
            {
                List <Amplifier> amplifiers = new List <Amplifier>();

                foreach (char setting in settings)
                {
                    Queue <int> inputs = new Queue <int>();
                    inputs.Enqueue(int.Parse(setting.ToString()));
                    amplifiers.Add(new Amplifier(inputs, intCode));
                }


                int input = 0;

                while (amplifiers[^ 1].Completed == false)