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. } } } }
public void Part1Tests(long[] instructions, long[] expectedOutput) { var intcodeRunner = new IntcodeRunner(instructions); var runnerResults = intcodeRunner.Execute(); runnerResults.Should().BeEquivalentTo(expectedOutput); }
public int Solve(string input, int pos1Value, int pos2Value) { var opcodes = input.ToOpcodes(); opcodes[1] = pos1Value; opcodes[2] = pos2Value; return(IntcodeRunner.Run(opcodes)[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(); }
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); }
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); }
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); } }
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]}"); }
public void Sample1() { var output = IntcodeRunner.Run("1,0,0,0,99".ToOpcodes()).ToStringValue(); Assert.Equal("2,0,0,0,99", output); }
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); }
public void Sample3() { var output = IntcodeRunner.Run("2,4,4,5,99,0".ToOpcodes()).ToStringValue(); Assert.Equal("2,4,4,5,99,9801", output); }