Ejemplo n.º 1
0
        public void ComputeConditionAdvanced()
        {
            // Arrange
            var program = new long[]
            {
                3, 21, 1008, 21, 8, 20, 1005, 20, 22, 107, 8, 21, 20, 1006, 20, 31,
                1106, 0, 36, 98, 0, 0, 1002, 21, 125, 20, 4, 20, 1105, 1, 46, 104,
                999, 1105, 1, 46, 1101, 1000, 1, 20, 4, 20, 1105, 1, 46, 98, 99
            };
            var computer = new Day5.IntComputer(program);

            const int expectedIfBelowEight       = 999;
            const int expectedIfEqualsToEight    = 1000;
            const int expectedIfGreaterThanEight = 1001;

            // Act
            var actualIfBelowEight       = computer.Compute(7);
            var actualIfEqualsToEight    = computer.Compute(8);
            var actualIfGreaterThanEight = computer.Compute(9);

            // Assert
            Assert.Equal(expectedIfBelowEight, actualIfBelowEight[0]);
            Assert.Equal(expectedIfEqualsToEight, actualIfEqualsToEight[0]);
            Assert.Equal(expectedIfGreaterThanEight, actualIfGreaterThanEight[0]);
        }
Ejemplo n.º 2
0
        private static long CalculateThrusterSignal(Day5.IntComputer computer, long[] phaseSettings)
        {
            var outputA = computer.Compute(phaseSettings[0], 0);
            var outputB = computer.Compute(phaseSettings[1], outputA[0]);
            var outputC = computer.Compute(phaseSettings[2], outputB[0]);
            var outputD = computer.Compute(phaseSettings[3], outputC[0]);
            var outputE = computer.Compute(phaseSettings[4], outputD[0]);

            return(outputE[0]);
        }
Ejemplo n.º 3
0
        private static (long actual, long noun, long verb) FindNounAndVerb(long expected)
        {
            var computer = new Day5.IntComputer(Day5.IntComputer.LoadProgram("Day2_input"));

            var actual = 0L;
            var noun   = 0L;
            var verb   = 0L;

            for (noun = 0L; noun <= 99; noun++)
            {
                for (verb = 0L; verb <= 99; verb++)
                {
                    computer.Program[1] = noun;
                    computer.Program[2] = verb;
                    computer.Compute();

                    actual = computer.Memory[0];

                    if (expected == actual)
                    {
                        break;
                    }
                }

                if (expected == actual)
                {
                    break;
                }
            }

            return(actual, noun, verb);
        }
Ejemplo n.º 4
0
        public void ComputeCondition(long[] program, long inputForTrue, long inputForFalse)
        {
            // Arrange
            var computer = new Day5.IntComputer(program);

            const int expectedTrue  = 1;
            const int expectedFalse = 0;

            // Act
            var actualTrue  = computer.Compute(inputForTrue);
            var actualFalse = computer.Compute(inputForFalse);

            // Assert
            Assert.Equal(expectedTrue, actualTrue[0]);
            Assert.Equal(expectedFalse, actualFalse[0]);
        }
Ejemplo n.º 5
0
        public void ComputeResult(long[] program, long[] expected)
        {
            // Arrange
            var computer = new Day5.IntComputer(program);

            // Act
            computer.Compute();
            var actual = computer.Memory.Select(cell => cell.Value);

            // Assert
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 6
0
        public void InputOutput()
        {
            // Arrange
            var computer = new Day5.IntComputer(3, 0, 4, 0, 99);
            var expected = new long[] { 15 };

            // Act
            var actual = computer.Compute(expected);

            // Assert
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 7
0
        public void RunBoostProgram()
        {
            // Arrange
            var computer = new Day5.IntComputer(Day5.IntComputer.LoadProgram("Day9_input"));

            var expectedOutput = new[] { 53088L };

            // Act
            var actualOutput = computer.Compute(2);

            // Assert
            Assert.Equal(expectedOutput, actualOutput);
        }
Ejemplo n.º 8
0
        public void TestBoostProgram()
        {
            // Arrange
            var computer = new Day5.IntComputer(Day5.IntComputer.LoadProgram("Day9_input"));

            var expectedOutput = new[] { 2350741403L };

            // Act
            var actualOutput = computer.Compute(1);

            // Assert
            Assert.Equal(expectedOutput, actualOutput);
        }
Ejemplo n.º 9
0
        public void ComputeResultFromInputAdvanced()
        {
            // Arrange
            var computer = new Day5.IntComputer(Day5.IntComputer.LoadProgram("Day5_input"));

            var expected = 9386583;

            // Act
            var actual = computer.Compute(5)[0];

            // Assert
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 10
0
        public void ComputeResultFromInput5()
        {
            // Arrange
            var computer = new Day5.IntComputer(Day5.IntComputer.LoadProgram("Day5_input"));

            var expected = 16489636;

            // Act
            var actual = computer.Compute(1);

            // Assert
            computer.DumpMemory("Day5_output");
            Assert.All(actual.Take(actual.Length - 1), i => Assert.Equal(0, i));
            Assert.Equal(expected, actual[actual.Length - 1]);
        }
Ejemplo n.º 11
0
        public void ComputeResultFromInput()
        {
            // Arrange

            var computer = new Day5.IntComputer(Day5.IntComputer.LoadProgram("Day2_input"));

            computer.Program[1] = 12;
            computer.Program[2] = 2;

            var expected = 6327510;

            // Act
            computer.Compute();
            var actual = computer.Memory[0];

            // Assert
            Assert.Equal(expected, actual);
        }