public void RunProgramComparisonTests() { // https://adventofcode.com/2019/day/5 // 3,9,8,9,10,9,4,9,99,-1,8 - Using position mode, consider whether the input is equal to 8; output 1 (if it is) or 0 (if it is not). // 3,9,7,9,10,9,4,9,99,-1,8 - Using position mode, consider whether the input is less than 8; output 1(if it is) or 0(if it is not). // 3,3,1108,-1,8,3,4,3,99 - Using immediate mode, consider whether the input is equal to 8; output 1(if it is) or 0(if it is not). // 3,3,1107,-1,8,3,4,3,99 - Using immediate mode, consider whether the input is less than 8; output 1(if it is) or 0(if it is not). var testData = new List <Tuple <int[], int, int> >(new Tuple <int[], int, int>[] { new Tuple <int[], int, int>(new int[] { 3, 9, 8, 9, 10, 9, 4, 9, 99, -1, 8 }, 7, 0), new Tuple <int[], int, int>(new int[] { 3, 9, 8, 9, 10, 9, 4, 9, 99, -1, 8 }, 8, 1), new Tuple <int[], int, int>(new int[] { 3, 9, 8, 9, 10, 9, 4, 9, 99, -1, 8 }, 9, 0), new Tuple <int[], int, int>(new int[] { 3, 9, 7, 9, 10, 9, 4, 9, 99, -1, 8 }, 7, 1), new Tuple <int[], int, int>(new int[] { 3, 9, 7, 9, 10, 9, 4, 9, 99, -1, 8 }, 8, 0), new Tuple <int[], int, int>(new int[] { 3, 9, 7, 9, 10, 9, 4, 9, 99, -1, 8 }, 9, 0), new Tuple <int[], int, int>(new int[] { 3, 3, 1108, -1, 8, 3, 4, 3, 99 }, 7, 0), new Tuple <int[], int, int>(new int[] { 3, 3, 1108, -1, 8, 3, 4, 3, 99 }, 8, 1), new Tuple <int[], int, int>(new int[] { 3, 3, 1108, -1, 8, 3, 4, 3, 99 }, 9, 0), new Tuple <int[], int, int>(new int[] { 3, 3, 1107, -1, 8, 3, 4, 3, 99 }, 7, 1), new Tuple <int[], int, int>(new int[] { 3, 3, 1107, -1, 8, 3, 4, 3, 99 }, 8, 0), new Tuple <int[], int, int>(new int[] { 3, 3, 1107, -1, 8, 3, 4, 3, 99 }, 9, 0), }); foreach (var testExample in testData) { var inputProvider = new StaticValueInputProvider(testExample.Item2); var outputListener = new ListOutputListener(); var computer = new IntcodeComputer(inputProvider, outputListener); computer.LoadProgram(testExample.Item1); var status = computer.RunProgram(); Assert.Equal(IntcodeProgramStatus.Completed, status); Assert.True(outputListener.Values.Count > 0); Assert.Equal(testExample.Item3, outputListener.Values[outputListener.Values.Count - 1]); } }
public void RunProgramJumpTests() { // https://adventofcode.com/2019/day/5 // Here are some jump tests that take an input, then output 0 if the input was zero or 1 if the input was non-zero: // 3,12,6,12,15,1,13,14,13,4,13,99,-1,0,1,9(using position mode) // 3,3,1105,-1,9,1101,0,0,12,4,12,99,1(using immediate mode) // The following example program uses an input instruction to ask // for a single number. The program will then output 999 if the // input value is below 8, output 1000 if the input value is equal // to 8, or output 1001 if the input value is greater than 8. // 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 testData = new List <Tuple <int[], int, int> >(new Tuple <int[], int, int>[] { new Tuple <int[], int, int>(new int[] { 3, 12, 6, 12, 15, 1, 13, 14, 13, 4, 13, 99, -1, 0, 1, 9 }, -1, 1), new Tuple <int[], int, int>(new int[] { 3, 12, 6, 12, 15, 1, 13, 14, 13, 4, 13, 99, -1, 0, 1, 9 }, 0, 0), new Tuple <int[], int, int>(new int[] { 3, 12, 6, 12, 15, 1, 13, 14, 13, 4, 13, 99, -1, 0, 1, 9 }, 1, 1), new Tuple <int[], int, int>(new int[] { 3, 3, 1105, -1, 9, 1101, 0, 0, 12, 4, 12, 99, 1 }, -1, 1), new Tuple <int[], int, int>(new int[] { 3, 3, 1105, -1, 9, 1101, 0, 0, 12, 4, 12, 99, 1 }, 0, 0), new Tuple <int[], int, int>(new int[] { 3, 3, 1105, -1, 9, 1101, 0, 0, 12, 4, 12, 99, 1 }, 1, 1), new Tuple <int[], int, int>(new int[] { 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 }, 7, 999), new Tuple <int[], int, int>(new int[] { 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 }, 8, 1000), new Tuple <int[], int, int>(new int[] { 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 }, 9, 1001) }); foreach (var testExample in testData) { var inputProvider = new StaticValueInputProvider(testExample.Item2); var outputListener = new ListOutputListener(); var computer = new IntcodeComputer(inputProvider, outputListener); computer.LoadProgram(testExample.Item1); var status = computer.RunProgram(); Assert.Equal(IntcodeProgramStatus.Completed, status); Assert.True(outputListener.Values.Count > 0); Assert.Equal(testExample.Item3, outputListener.Values[outputListener.Values.Count - 1]); } }
public static BigInteger GetDay9Part2Answer() { // The program runs in sensor boost mode by providing the input // instruction the value 2. Once run, it will boost the sensors // automatically, but it might take a few seconds to complete the // operation on slower hardware. In sensor boost mode, the program // will output a single value: the coordinates of the distress signal. // Run the BOOST program in sensor boost mode.What are the // coordinates of the distress signal? // Answer: 63441 var program = GetDay9Input(); var inputProvider = new StaticValueInputProvider(2); var outputListener = new ListOutputListener(); var computer = new IntcodeComputer(inputProvider, outputListener); computer.LoadProgram(program); computer.RunProgram(); return(outputListener.Values[0]); }
public static BigInteger GetDay9Part1Answer() { // The BOOST program will ask for a single input; run it in test // mode by providing it the value 1. It will perform a series of // checks on each opcode, output any opcodes (and the associated // parameter modes) that seem to be functioning incorrectly, and // finally output a BOOST keycode. // Once your Intcode computer is fully functional, the BOOST // program should report no malfunctioning opcodes when run in test // mode; it should only output a single value, the BOOST keycode. // What BOOST keycode does it produce? // Answer: 2662308295 var program = GetDay9Input(); var inputProvider = new StaticValueInputProvider(1); var outputListener = new ListOutputListener(); var computer = new IntcodeComputer(inputProvider, outputListener); computer.LoadProgram(program); computer.RunProgram(); return(outputListener.Values[0]); }