示例#1
0
        public void Part2Tests_File()
        {
            const int outputToFind = 19690720;
            var       instructions = File.ReadAllText(InputFile)
                                     .Split(',')
                                     .Select(x => long.Parse(x))
                                     .ToArray();

            var intcodeRunner = new IntcodeRunner(instructions);

            for (int noun = 0; noun <= 99; noun++)
            {
                for (int verb = 0; verb <= 99; verb++)
                {
                    try
                    {
                        var runnerResults = intcodeRunner.Execute(noun, verb);
                        if (runnerResults[0] == outputToFind)
                        {
                            Console.WriteLine($"Found Matching Result: Noun={noun}, Verb={verb}");
                            Console.WriteLine($"  Output: {noun * 100 + verb}");
                        }
                    }
                    catch
                    {
                        // If the program encounters an error, ignore it as it means the values didn't result in the desired output.
                    }
                }
            }
        }
示例#2
0
        public void Part1Tests(long[] instructions, long[] expectedOutput)
        {
            var intcodeRunner = new IntcodeRunner(instructions);
            var runnerResults = intcodeRunner.Execute();

            runnerResults.Should().BeEquivalentTo(expectedOutput);
        }
示例#3
0
        public int Solve(string input, int pos1Value, int pos2Value)
        {
            var opcodes = input.ToOpcodes();

            opcodes[1] = pos1Value;
            opcodes[2] = pos2Value;

            return(IntcodeRunner.Run(opcodes)[0]);
        }
示例#4
0
        public void Part2Tests_File()
        {
            var instructions = File.ReadAllText(InputFile1)
                               .Split(",")
                               .Select(x => long.Parse(x))
                               .ToArray();
            var intcodeRunner = new IntcodeRunner(instructions);

            intcodeRunner.InputQueue.Enqueue(2);

            var runnerResults = intcodeRunner.Execute();
        }
示例#5
0
        public void Part2Tests(long[] instructions, long[] userInput, long[] expectedOutput)
        {
            var intcodeRunner = new IntcodeRunner(instructions);

            foreach (var item in userInput)
            {
                intcodeRunner.InputQueue.Enqueue(item);
            }

            var runnerResults = intcodeRunner.Execute();

            runnerResults.Should().BeEquivalentTo(expectedOutput);
        }
示例#6
0
        public void Part2Tests_File()
        {
            var instructions = File.ReadAllText(InputFile1)
                               .Split(',')
                               .Select(x => long.Parse(x))
                               .ToArray();

            var intcodeRunner = new IntcodeRunner(instructions);

            intcodeRunner.InputQueue.Enqueue(5);
            var runnerResults = intcodeRunner.Execute();

            intcodeRunner.GetLastOutput().Should().Be(9168267);
        }
示例#7
0
        public void Part1Tests(long[] instructions, long expected, long[] expectedArr)
        {
            var intcodeRunner = new IntcodeRunner(instructions);
            var runnerResults = intcodeRunner.Execute();

            if (expectedArr != null)
            {
                runnerResults.Should().BeEquivalentTo(expectedArr);
            }
            else
            {
                intcodeRunner.GetLastOutput().Should().Be(expected);
            }
        }
示例#8
0
        public void Part1Tests_File()
        {
            var instructions = File.ReadAllText(InputFile)
                               .Split(',')
                               .Select(x => long.Parse(x))
                               .ToArray();

            // Restore gravity assist.
            var noun = 12;
            var verb = 2;

            var intcodeRunner = new IntcodeRunner(instructions);
            var runnerResults = intcodeRunner.Execute(noun, verb);

            Console.WriteLine($"Position 0 Result: {runnerResults[0]}");
        }
示例#9
0
        public void Sample1()
        {
            var output = IntcodeRunner.Run("1,0,0,0,99".ToOpcodes()).ToStringValue();

            Assert.Equal("2,0,0,0,99", output);
        }
示例#10
0
        public void Sample4()
        {
            var output = IntcodeRunner.Run("1,1,1,4,99,5,6,0,99".ToOpcodes()).ToStringValue();

            Assert.Equal("30,1,1,4,2,5,6,0,99", output);
        }
示例#11
0
        public void Sample3()
        {
            var output = IntcodeRunner.Run("2,4,4,5,99,0".ToOpcodes()).ToStringValue();

            Assert.Equal("2,4,4,5,99,9801", output);
        }