Esempio n. 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}");
        }
Esempio n. 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}");
        }
Esempio n. 3
0
        public void DoAction1()
        {
            var content = ReadFile();

            var intComputer = new IntComputer(content, false);

            intComputer.Memory[1] = 12;
            intComputer.Memory[2] = 2;
            intComputer.Run();

            Console.WriteLine($"Output {intComputer.Memory[0]}");
        }
Esempio n. 4
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));
        }
Esempio n. 5
0
        public void DoAction2()
        {
            var content = ReadFile();

            var loopLength = 100;

            for (var a = 0; a < loopLength; a++)
            {
                for (var b = 0; b < loopLength; b++)
                {
                    var intComputer = new IntComputer(content, false);
                    intComputer.Memory[1] = a;
                    intComputer.Memory[2] = b;
                    intComputer.Run();

                    if (intComputer.Memory[0] == 19690720)
                    {
                        Console.WriteLine($"Output {intComputer.Memory[0]} for Noun {a} and Verb {b}");
                        a = loopLength;
                        b = loopLength;
                    }
                }
            }
        }