/// <summary> /// Paints the hull with the given int code /// </summary> /// <param name="startColor">0 - Black, 1 - White</param> public void Paint(int startColor) { PaintPanel(CurrentPosition, startColor); SetNextInput(); io.SentOutput += Io_SentOutput; _intCode.ContinueAfterOutput = true; _intCode.Compute(); }
public void Day2Test(List <long> code, List <long> outCode) { var io = new IntCodeComputerIO(new List <long>()); var intCodeComputer = new IntCodeComputerInstance(code, io, io); intCodeComputer.Compute(); Assert.IsTrue(intCodeComputer.Code.SequenceEqual(outCode)); }
/// <summary> /// Explores the area the droid is located in /// </summary> public void Explore() { _currentLocation = new IntVector(0, 0); _openSpace.Add(_currentLocation); Enum.GetValues(typeof(MovementCommands)).Cast <MovementCommands>().Skip(1).ToList().ForEach(c => _commands.Push(c)); while (_commands.Count != 0) { _computer.Compute(); } }
/// <summary> /// Execution function for Day 2 /// </summary> public void Execute2() { UserActionAsync(() => { WriteToConsole("Start execution of Day2"); var parser = GetInputParser("Day2Input.txt"); var originalCode = parser.GetIntCode(); var code = originalCode.ToList(); code[1] = 12; code[2] = 2; var input = new PopupInput("No input needed"); var intComputer = new IntCodeComputerInstance(code, input, _consoleOutput); intComputer.Compute(); WriteToConsole($"After execution the value at position 0 is {intComputer.Code[0].ToString("N")}"); AddEmptyLine(); WriteToConsole("For part 2 we need to find the inputs that produce the output 19690720"); int finalNoun = -1; int finalVerb = -1; for (int noun = 0; noun <= 99; noun++) { for (int verb = 0; verb <= 99; verb++) { var testCode = originalCode.ToList(); testCode[1] = noun; testCode[2] = verb; intComputer = new IntCodeComputerInstance(testCode, input, _consoleOutput); intComputer.Compute(); if (intComputer.Code[0] == 19690720) { finalNoun = noun; finalVerb = verb; //Breaks the outer loop noun = 100; break; } } } WriteToConsole($"Found the correct inputs: Noun = {finalNoun}, Verb = {finalVerb}. 100 * Noun + verb = {100 * finalNoun + finalVerb}"); AddEmptyLine(); }); }
public void Day5Part2Test(List <long> code, int input, int expectedOutput) { var io = new IntCodeComputerIO(new List <long>() { input }); long output = default; var outputFunc = new DelegateOutput((long i) => output = i); var intCodeComputer = new IntCodeComputerInstance(code, io, outputFunc); intCodeComputer.Compute(); Assert.IsTrue(output == expectedOutput); }
/// <summary> /// Execution function for Day 9 /// </summary> public void Execute9() { UserActionAsync(() => { WriteToConsole("Start execution of Day9"); var parser = GetInputParser("Day9Input.txt"); var originalCode = parser.GetIntCode(); var code = originalCode.ToList(); var input = new PopupInput("Start BOOST. Inputs:\n1 - Test Mode\n2 - Sensor Boost Mode"); var intComputer = new IntCodeComputerInstance(code, input, _consoleOutput); intComputer.Compute(); WriteToConsole($"Finished BOOST"); AddEmptyLine(); }); }
public void Day9Test3() { var code = new List <long>() { 104, 1125899906842624, 99 }; var io = new IntCodeComputerIO(new List <long>()); long output = default; var outputFunc = new DelegateOutput((long i) => output = i); var intCodeComputer = new IntCodeComputerInstance(code, io, outputFunc); intCodeComputer.ContinueAfterOutput = true; intCodeComputer.Compute(); Assert.IsTrue(1125899906842624 == output); }
public void Day9Test2() { var code = new List <long>() { 1102, 34915192, 34915192, 7, 4, 7, 99, 0 }; var io = new IntCodeComputerIO(new List <long>()); long output = default; var outputFunc = new DelegateOutput((long i) => output = i); var intCodeComputer = new IntCodeComputerInstance(code, io, outputFunc); intCodeComputer.ContinueAfterOutput = true; intCodeComputer.Compute(); Assert.IsTrue(16 == output.ToString().Length); }
/// <summary> /// Execution function for Day 5 /// </summary> public void Execute5() { UserActionAsync(() => { WriteToConsole("Start execution of Day5"); var parser = GetInputParser("Day5Input.txt"); var originalCode = parser.GetIntCode(); var code = originalCode.ToList(); var input = new PopupInput("Started Diagnostics. Inputs:\n1 - air conditioner unit\n5 - thermal radiator controller"); var intComputer = new IntCodeComputerInstance(code, input, _consoleOutput); intComputer.ContinueAfterOutput = true; intComputer.Compute(); WriteToConsole($"Diagnostics finished"); AddEmptyLine(); }); }
public void Day9Test1() { var origCode = new List <long>() { 109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0, 99 }; var code = origCode.ToList(); var io = new IntCodeComputerIO(new List <long>()); var output = new List <long>(); var outputFunc = new DelegateOutput((long i) => output.Add(i)); var intCodeComputer = new IntCodeComputerInstance(code, io, outputFunc); intCodeComputer.ContinueAfterOutput = true; intCodeComputer.Compute(); Assert.IsTrue(origCode.SequenceEqual(output)); }