public void Part1_RelativeExample() { var compiler = new IntCodeCompiler(); var program = compiler.ComputeStep(new IntCodeProgram(new long[] { 109, 19 }, 0, 2000)); Assert.AreEqual(2019, program.RelativeBaseOffset); }
public void Part1_RelativeMultipleTime() { var compiler = new IntCodeCompiler(); var program = compiler.Compute(new IntCodeProgram(new long[] { 109, 1, 109, 1, 109, 1, 109, 1, 99 }, 0, 0)); Assert.AreEqual(4, program.RelativeBaseOffset, "The relative Offset should be set to 1"); }
public void Exemple13() { var input = new long[] { 3500, 9, 10, 70, 2, 3, 11, 0, 99, 30, 40, 50 }; var expected = new long[] { 3500, 9, 10, 70, 2, 3, 11, 0, 99, 30, 40, 50 }; TestUtility.AreEqual(expected, IntCodeCompiler.ComputeStep(input, 8)); }
public void Part1_KeepRelativeBase() { var compiler = new IntCodeCompiler(new long[] { 1 }); var program = compiler.Compute(new IntCodeProgram(new long[] { 1101, 2, 3, 3, 99 }, 0, 1)); Assert.AreEqual(1, program.RelativeBaseOffset, "The relative Offset should be stay to 1 after an Addition"); program = compiler.Compute(new IntCodeProgram(new long[] { 1102, 2, 3, 3, 99 }, 0, 1)); Assert.AreEqual(1, program.RelativeBaseOffset, "The relative Offset should be stay to 1 after an Multiply"); program = compiler.Compute(new IntCodeProgram(new long[] { 3, 0, 99 }, 0, 1)); Assert.AreEqual(1, program.RelativeBaseOffset, "The relative Offset should be stay to 1 after an Input"); program = compiler.Compute(new IntCodeProgram(new long[] { 4, 0, 99 }, 0, 1)); Assert.AreEqual(1, program.RelativeBaseOffset, "The relative Offset should be stay to 1 after an ouput"); program = compiler.Compute(new IntCodeProgram(new long[] { 1105, 1, 3, 99 }, 0, 1)); Assert.AreEqual(1, program.RelativeBaseOffset, "The relative Offset should be stay to 1 after an JumpIfTrue"); program = compiler.Compute(new IntCodeProgram(new long[] { 1106, 1, 3, 99 }, 0, 1)); Assert.AreEqual(1, program.RelativeBaseOffset, "The relative Offset should be stay to 1 after an JumpIfFalse"); program = compiler.Compute(new IntCodeProgram(new long[] { 1107, 1, 3, 0, 99 }, 0, 1)); Assert.AreEqual(1, program.RelativeBaseOffset, "The relative Offset should be stay to 1 after an LessThen"); program = compiler.Compute(new IntCodeProgram(new long[] { 1108, 1, 3, 0, 99 }, 0, 1)); Assert.AreEqual(1, program.RelativeBaseOffset, "The relative Offset should be stay to 1 after an Equal"); }
public void Exemple4() { var input = new long[] { 2, 4, 4, 5, 99, 0 }; var expected = new long[] { 2, 4, 4, 5, 99, 9801 }; TestUtility.AreEqual(expected, IntCodeCompiler.ComputeStep(input)); }
public void Exemple3() { var input = new long[] { 2, 3, 0, 3, 99 }; var expected = new long[] { 2, 3, 0, 6, 99 }; TestUtility.AreEqual(expected, IntCodeCompiler.ComputeStep(input)); }
public void Exemple5() { var input = new long[] { 1, 1, 1, 4, 99, 5, 6, 0, 99 }; var expected = new long[] { 30, 1, 1, 4, 2, 5, 6, 0, 99 }; TestUtility.AreEqual(expected, IntCodeCompiler.Compute(input)); }
public static void ConvertWhileRunning(IntCodeCompiler intCodeCompiler, IntCodeProgram program, string filename, bool useExecutorActionForMain) { string output = ""; int maxSteps = 100; while (!program.IsDone || maxSteps-- > 0) { var instruction = program.OpCodeAtPointer; var opcode = instruction % 100; if (opcode == 99) { output += "Halt"; break; } else if (opcode > intCodeCompiler.Instructions.Length || intCodeCompiler.Instructions[opcode] == null) { output += $"! Missing Instruction {opcode}!\n"; break; } else { output += InstructionToCode(program, instruction, opcode, program.Pointer); program = intCodeCompiler.ComputeStep(program); } } if (useExecutorActionForMain) { AOCExecutor.ActionForMain.Enqueue(() => AOCInput.WriteToFile(filename, output)); } else { AOCInput.WriteToFile(filename, output); } }
public static void Convert(IntCodeProgram program, string filename) { var compiler = new IntCodeCompiler(); string output = ""; long pointer = 0; while (pointer < program.MemoryLength) { var instruction = program[pointer]; var opcode = instruction % 100; if (opcode == 99) { output += "Halt"; break; } else if (opcode > compiler.Instructions.Length || compiler.Instructions[opcode] == null) { output += "! Missing Instruction !\n"; break; } else { output += InstructionToCode(program, instruction, opcode, pointer); pointer += compiler.InstructionsSkips[opcode]; } } if (Application.isPlaying) { AOCExecutor.ActionForMain.Enqueue(() => AOCInput.WriteToFile(filename, output)); } else { AOCInput.WriteToFile(filename, output); } }
public static long[] ComputeStep(long[] memory, long startingPointer = 0) { var program = new IntCodeProgram(memory, startingPointer); var compiler = new IntCodeCompiler(); return(compiler.ComputeStep(program)); }
public void Part1_RelativeExample() { var compiler = new IntCodeCompiler(); var program = compiler.Compute(new IntCodeProgram(new long[] { 104, 1, 104, 2, 104, 3, 104, 4, 99 }, 0, 0)); Assert.AreEqual(false, compiler.Paused, "Should Not be paused"); Assert.AreEqual(1234, compiler.OutputValue, "" + compiler.OutputAasListIntStr); }
public void Part1_RelativeExampleComplete() { var compiler = new IntCodeCompiler(); var program = compiler.Compute(new IntCodeProgram(new long[] { 109, 1, 204, 1, 99 }, 0, 0)); Assert.AreEqual(1, program.RelativeBaseOffset, "The relative Offset should be set to 1"); Assert.AreEqual(204, compiler.OutputValue); }
public void Part1_Relative2() { var compiler = new IntCodeCompiler(); var program = compiler.Compute(new IntCodeProgram(new long[] { 204, 0, 109, -1, 204, 5, 99 }, 0, 2)); Assert.AreEqual(1, program.RelativeBaseOffset, "The relative Offset should be set to 1"); Assert.AreEqual(10999, compiler.OutputValue); }
public void Part1_LargestNumber() { var intcode = new long[] { 104, 1125899906842624, 99 }; var compiler = new IntCodeCompiler(); compiler.Compute(new IntCodeProgram(intcode, 0)); Assert.AreEqual(1125899906842624, compiler.OutputValue); }
public void Part1_16DigitNumber() { var intcode = new long[] { 1102, 34915192, 34915192, 7, 4, 7, 99, 0 }; var compiler = new IntCodeCompiler(); compiler.Compute(new IntCodeProgram(intcode, 0)); Assert.AreEqual(34915192L * 34915192L, compiler.OutputValue); }
public static long Part2(string inputText) { var intcode = InputParser.ListOfLongs(inputText, ','); var compiler = new IntCodeCompiler(0, true); intcode[0] = 2; var program = new IntCodeProgram(intcode, 0); var level = new TileType[100, 100]; int ballPosition = 0; int paddlePosition = 0; int blockRemaining = 261; int maxBreak = 25000; long score = 0; while (--maxBreak > 0 && !program.IsDone && blockRemaining > 0) { paddlePosition = FindXOfTileTyle(TileType.Paddle, level); ballPosition = FindXOfTileTyle(TileType.Ball, level); if (paddlePosition < ballPosition) { compiler.SetInputs(new long[] { 1 }); } else if (paddlePosition > ballPosition) { compiler.SetInputs(new long[] { -1 }); } else { compiler.SetInputs(new long[] { 0 }); } compiler.Clear(); program = compiler.Compute(program); program = compiler.Compute(program); program = compiler.Compute(program); if (compiler.OutputValues[0] == -1 && compiler.OutputValues[1] == 0) { blockRemaining--; score = compiler.OutputValues[2]; Debug.Log($"{blockRemaining} block remainning. Score : {score}"); } else { var x = compiler.OutputValues[0]; var y = compiler.OutputValues[1]; var tileType = (int)compiler.OutputValues[2]; level[y, x] = IdToTileType(tileType); } } Debug.Log($"maxBreak:{maxBreak}, "); return(score); }
public void Part1_QuineSelfReplicating() { var intcode = new long[] { 109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0, 99 }; var compiler = new IntCodeCompiler(); compiler.Compute(new IntCodeProgram(intcode.ToArray(), 0)); IntCodeToBasic.ConvertWhileRunning(intcode.ToArray(), "Day9_Part1_QuineSelfReplicating.txt", false); TestUtility.AreEqual(intcode, compiler.OutputValues.ToArray()); }
public void Part1_OutsideMemory() { var compiler = new IntCodeCompiler(new long[] { 69 }); var program = compiler.Compute(new IntCodeProgram(new long[] { 03, 5, 04, 5, 99 }, 0, 2)); Assert.AreEqual(2, program.RelativeBaseOffset, "The relative Offset should be set to 0"); TestUtility.AreEqual(new long[] { 03, 5, 04, 5, 99, 69 }, program.Memory.ToArray()); Assert.AreEqual(69, compiler.OutputValue); }
public void TestGiven2() { var icc = new IntCodeCompiler("1", new List <long> { 1102, 34915192, 34915192, 7, 4, 7, 99, 0 }, false); icc.Calculate(); Assert.AreEqual(16, icc.LastOutput.ToString().Length); }
public void TestGiven3() { var icc = new IntCodeCompiler("1", new List <long> { 104, 1125899906842624, 99 }, false); icc.Calculate(); Assert.AreEqual(1125899906842624, icc.LastOutput); }
public void TestGiven() { var icc = new IntCodeCompiler("1", new List <long> { 109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0, 99 }, false); icc.Calculate(); Assert.AreEqual(99, icc.LastOutput); }
public void Part1Answer() { var intcode = InputParser.ListOfLongs(Day5Input, ','); var compiler = new IntCodeCompiler(1); compiler.Compute(new IntCodeProgram(intcode, 0)); Assert.AreEqual("30000000013978427", compiler.OutputConcat); }
public void Part2Answer() { var intcode = InputParser.ListOfLongs(Day5Input, ','); var compiler = new IntCodeCompiler(5); compiler.Compute(new IntCodeProgram(intcode, 0)); Assert.AreEqual("11189491", compiler.OutputConcat); }
public static string Part1(string inputText) { var intcode = InputParser.ListOfLongs(inputText, ','); var compiler = new IntCodeCompiler(1); var program = new IntCodeProgram(intcode, 0); compiler.Compute(program); IntCodeToBasic.Convert(program, "D5Part1HumainCode.txt"); return(compiler.OutputConcat); }
public void Part1() { var intcode = InputParser.ListOfLongs(Day9Input, ','); IntCodeToBasic.ConvertWhileRunning(new IntCodeCompiler(1), new IntCodeProgram(intcode.ToArray(), 0), "D9Part1_HumainCode.txt", false); var compiler = new IntCodeCompiler(1); compiler.Compute(new IntCodeProgram(intcode, 0)); Assert.AreEqual(3533056970, compiler.OutputValue); }
public static string Part2(string inputText) { var intcode = InputParser.ListOfLongs(inputText, ','); IntCodeToBasic.ConvertWhileRunning(new IntCodeCompiler(5), new IntCodeProgram(intcode.ToArray(), 0), "D5Part2HumainCode.txt", true); var compiler = new IntCodeCompiler(5); compiler.Compute(new IntCodeProgram(intcode, 0)); return(compiler.OutputConcat); }
public void TestGiven5a(int i, int e) { IList <long> input = new List <long> { 3, 12, 6, 12, 15, 1, 13, 14, 13, 4, 13, 99, -1, 0, 1, 9 }; var inputs = new Queue <long>(); inputs.Enqueue(i); var icc = new IntCodeCompiler(input, inputs); icc.Calculate(); Assert.AreEqual(e, icc.LastOutput); }
public void Part2() { var intcode = InputParser.ListOfLongs(Day9Input, ','); //Trop long !! //IntCodeToBasic.ConvertWhileRunning(new IntCodeCompiler(2), new IntCodeProgram(intcode.ToArray(), 0), "D9Part2_HumainCode.txt", false); var compiler = new IntCodeCompiler(2); compiler.Compute(new IntCodeProgram(intcode, 0)); Assert.AreEqual(1930, compiler.OutputValue); }
public void TestGiven6(int i, int e) { IList <long> input = new List <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 inputs = new Queue <long>(); inputs.Enqueue(i); var icc = new IntCodeCompiler(input, inputs); icc.Calculate(); Assert.AreEqual(e, icc.LastOutput); }
public void TestGiven4(int i, int e) { IList <long> input = new List <long> { 3, 3, 1107, -1, 8, 3, 4, 3, 99 }; var inputs = new Queue <long>(); inputs.Enqueue(i); var icc = new IntCodeCompiler(input, inputs); icc.Calculate(); Assert.AreEqual(e, icc.LastOutput); }