Пример #1
0
        public void DoAction2()
        {
            var content  = ReadFile();
            var computer = new IntComputer(content, false);

            computer.SetInputValues(2);
            computer.Run();
            Console.WriteLine($"Last output = {computer.LastOutput}");
        }
Пример #2
0
        public void DoAction1()
        {
            Console.WriteLine("Reading file");

            var content = ReadFile();

            var possibilities = new List <Amplification>();

            for (int a = 0; a < 5; a++)
            {
                for (int b = 0; b < 5; b++)
                {
                    for (int c = 0; c < 5; c++)
                    {
                        for (int d = 0; d < 5; d++)
                        {
                            for (int e = 0; e < 5; e++)
                            {
                                if (a == b || a == c || a == d || a == e ||
                                    b == c || b == d || b == e ||
                                    c == d || c == e ||
                                    d == e)
                                {
                                    break;
                                }

                                var ampA = new IntComputer(content, false);
                                ampA.SetInputValues(a, 0);
                                ampA.Run();
                                var ampB = new IntComputer(content, false);
                                ampB.SetInputValues(b, ampA.LastOutput);
                                ampB.Run();
                                var ampC = new IntComputer(content, false);
                                ampC.SetInputValues(b, ampB.LastOutput);
                                ampC.Run();
                                var ampD = new IntComputer(content, false);
                                ampD.SetInputValues(b, ampC.LastOutput);
                                ampD.Run();
                                var ampE = new IntComputer(content, false);
                                ampE.SetInputValues(b, ampD.LastOutput);
                                ampE.Run();

                                possibilities.Add(new Amplification {
                                    A = a, B = b, C = c, D = d, E = e, Output = ampE.LastOutput
                                });
                            }
                        }
                    }
                }
            }

            var highestOutput = possibilities.First(x => x.Output == possibilities.Max(y => y.Output));

            Console.WriteLine($"Configuration {highestOutput.A}{highestOutput.B}{highestOutput.C}{highestOutput.D}{highestOutput.E} gives the highest output of {highestOutput.Output}");
        }
Пример #3
0
        public void DoAction2() //742621
        {
            Console.WriteLine("Reading file");

            var fileReader = new StreamReader("./Input/Day05.txt");
            var content    = fileReader.ReadToEnd();

            var intcodeComputer = new IntComputer(content, false);

            intcodeComputer.SetInputValues(1);
            intcodeComputer.Run();

            Console.WriteLine(intcodeComputer.OutputValues.First(x => x != 0));
        }