public override void Initialize() { base.Initialize(); computer = new IntComputer(lines); computer.Load(); computer.Run(); viewData = new Dictionary <IntVector2, int>(); IntVector2 origin = new IntVector2(0, 0); while (computer.HasOutputs()) { int output = (int)computer.GetOutput(); if (output == 10) { origin.X = 0; origin.Y++; continue; } viewData.Add(new IntVector2(origin.X, origin.Y), output); origin.X++; } }
public Robot(int x, int y, string[] program) { direction = Direction.Up; position = new IntVector2(x, y); computer = new IntComputer(program); computer.Load(); }
public Day2() { var computer = new IntComputer(DefaultInput); computer.RunProgramDay2Part1(); computer.RunProgramDay2Part2(); }
static long RunDroid(IntComputer ic, string s) { int i = 0; int ret = 0; long lastOut = 0; do { lastOut = ic.reg; ic.reg = s[Math.Min(i, s.Length - 1)]; ret = ic.Execute(); if (ret == 2) { i++; } else if (ret == 3) { if (ic.reg < 255) { Console.Write((char)ic.reg); } } }while (ret > 0); return(lastOut); }
static bool SquareFits(IntComputer ic, int xStart, int yMax, ref Position pos) { Position dw = new Position(99, 0); Position dh = new Position(0, 99); Position blPos = new Position(xStart, yMax); while (ReadPosition(ic, blPos) != 1) { blPos += goRight; } Position brPos = blPos + dw; Position tlPos = blPos - dh; Position trPos = tlPos + dw; List <Position> positions = new List <Position>() { brPos, tlPos, trPos }; bool allFit = true; foreach (Position p in positions) { if (ReadPosition(ic, p) != 1) { allFit = false; } } if (allFit) { pos = tlPos; } return(allFit); }
public void SixteenDigitTest() { var computer = new IntComputer(new long[] { 1102, 34915192, 34915192, 7, 4, 7, 99 }); computer.Run(); Assert.AreEqual(16, computer.GetOutput().ToString().Length); }
void dfs(long input, HashSet <int> prev, long[] memory) { if (prev.Count == 5) { max = input > max ? input : max; return; } for (int i = 0; i < 5; i++) { if (!prev.Contains(i)) { long output; IntComputer intComputer = new IntComputer(memory); bool halt = intComputer.GetDiagnosticCode(new List <long>() { i, input }, out output); HashSet <int> next = new HashSet <int>(prev); next.Add(i); dfs(output, next, memory); } } }
public void Day2Part2Test() { for (long noun = 0; noun <= 99; noun++) { for (long verb = 0; verb <= 99; verb++) { var computer = new IntComputer(new long[] { 1, 12, 2, 3, 1, 1, 2, 3, 1, 3, 4, 3, 1, 5, 0, 3, 2, 10, 1, 19, 1, 19, 5, 23, 1, 23, 9, 27, 2, 27, 6, 31, 1, 31, 6, 35, 2, 35, 9, 39, 1, 6, 39, 43, 2, 10, 43, 47, 1, 47, 9, 51, 1, 51, 6, 55, 1, 55, 6, 59, 2, 59, 10, 63, 1, 6, 63, 67, 2, 6, 67, 71, 1, 71, 5, 75, 2, 13, 75, 79, 1, 10, 79, 83, 1, 5, 83, 87, 2, 87, 10, 91, 1, 5, 91, 95, 2, 95, 6, 99, 1, 99, 6, 103, 2, 103, 6, 107, 2, 107, 9, 111, 1, 111, 5, 115, 1, 115, 6, 119, 2, 6, 119, 123, 1, 5, 123, 127, 1, 127, 13, 131, 1, 2, 131, 135, 1, 135, 10, 0, 99, 2, 14, 0, 0 }); computer.SetNoun(noun); computer.SetVerb(verb); computer.Run(); if (computer.GetResult() == 19690720) { Assert.AreEqual(52, computer.GetNoun()); Assert.AreEqual(96, computer.GetVerb()); Assert.AreEqual(5296, 100 * noun + verb); } } } }
public void ModeTest3() { var computer = new IntComputer(new long[] { 1101, 100, -1, 4, 0 }); computer.Run(true); Assert.AreEqual(1101, computer.GetResult()); }
public void ModeTest1() { var computer = new IntComputer(new long[] { 1002, 4, 3, 4, 33 }); computer.Run(true); Assert.AreEqual(1002, computer.GetResult()); }
public int[] TestCanRunIntCode(int[] intCode) { var computer = new IntComputer(intCode); computer.Run(); return(intCode); }
static void PartA() { List <long> input = ReadInput(); IntComputer a = new IntComputer(input, 0); a.Execute(); Console.WriteLine("Part A: Result is {0}", a.paintedPos.Count); }
static void Main(string[] args) { while (true) { var computer = new IntComputer(File.ReadAllText("./input.txt")); computer.Run(); } }
public int[] TestIntComputerMemoryState(int[] intCode) { var computer = new IntComputer(intCode, 0); computer.Run(); return(intCode); }
public void LargeOutputTest() { const long bigNumber = 1125899906842624; var computer = new IntComputer(new long[] { 104, bigNumber, 99 }); computer.Run(); Assert.AreEqual(bigNumber, computer.GetOutput()); }
static void Main(string[] args) { int dims = 96; bool[,] map = new bool[dims, dims]; Vec2i pos = new Vec2i(dims / 2, dims / 2); HashSet <Vec2i> painted = new HashSet <Vec2i>(); Dictionary <int, Vec2i> offsets = new Dictionary <int, Vec2i>() { { 0, new Vec2i(1, 0) }, { 90, new Vec2i(0, 1) }, { 180, new Vec2i(-1, 0) }, { 270, new Vec2i(0, -1) }, }; int direction = 90; int count = 0; bool white = false; map[pos.X, pos.Y] = true; var computer = new IntComputer(File.ReadAllText("./input.txt")); computer.Input = () => { return(map[pos.X, pos.Y] ? 1 : 0); }; computer.Output = (o) => { if (count % 2 == 0) { white = o == 1; map[pos.X, pos.Y] = white; painted.Add(pos); } else { direction = (direction + (o == 1 ? -90 : 90) + 720) % 360; var offset = offsets[direction]; pos += offset; } count++; }; computer.Run(); Console.WriteLine($"Finished execution, {painted.Count} tiles were painted"); for (int y = 0; y < dims; y++) { for (int x = 0; x < dims; x++) { Console.Write(map[x, dims - y - 1] ? "*" : " "); } Console.WriteLine(); } }
static Object PartB() { List <long> input = ReadInput(); IntComputer c0 = new IntComputer(input, 0); long b = RunDroid(c0, springScriptB); Console.WriteLine("Part B: Result is {0}", b); return(b); }
static bool PartA(Object correctAnswer = null) { List <long> input = ReadInput(); IntComputer a = new IntComputer(input, 0); a.Execute(); Console.WriteLine("Part A: Result is {0}", a.paintedPos.Count); return(correctAnswer == null || a.paintedPos.Count == (int)correctAnswer); }
static bool PartB(Object correctAnswer = null) { List <long> input = ReadInput(); IntComputer c0 = new IntComputer(input, 0); long b = RunDroid(c0, springScriptB); Console.WriteLine("Part B: Result is {0}", b); return(correctAnswer == null || b == (long)correctAnswer); }
static Object PartB() { List <long> input = ReadInput(); IntComputer c0 = new IntComputer(input, 0); int b = RunNetworkB(c0); Console.WriteLine("Part B: Result is {0}", b); return(b); }
static Object PartA() { List <long> input = ReadInput(); IntComputer c0 = new IntComputer(input, 0); int a = RunNetworkA(c0); Console.WriteLine("Part A: Result is {0}", a); return(a); }
public static void Main() { var intCodes = System.IO.File .ReadAllText( "C:\\Users\\aarondk\\source\\repos\\AdventOfCode-CSharp\\AdventOfCode-CSharp\\Resources\\Day21.txt") .Split(",").Select(long.Parse).ToList(); var instructions = System.IO.File .ReadAllText( "C:\\Users\\aarondk\\source\\repos\\AdventOfCode-CSharp\\AdventOfCode-CSharp\\Resources\\Day21Instruction.txt"); var instructions2 = System.IO.File .ReadAllText( "C:\\Users\\aarondk\\source\\repos\\AdventOfCode-CSharp\\AdventOfCode-CSharp\\Resources\\Day21InstructionP2.txt"); var intComputer = new IntComputer { IntCodes = intCodes.Select(i => i).ToList() }; foreach (var el in instructions) { if (el == 13) { continue; } intComputer.Input.Enqueue(el); } intComputer.Start(); var output = intComputer.DumpFullOutput(); foreach (var el in output) { Console.Write((char)el); } Console.WriteLine($"Part1: amount of hull damage {output.Last()}"); var intComputer2 = new IntComputer { IntCodes = intCodes.Select(i => i).ToList() }; foreach (var el in instructions2) { if (el == 13) { continue; } intComputer2.Input.Enqueue(el); } intComputer2.Start(); var output2 = intComputer2.DumpFullOutput(); foreach (var el in output2) { Console.Write((char)el); } Console.WriteLine($"Part2: amount of hull damage {output2.Last()}"); }
public IntComputer(IntComputer c) { mem = new Dictionary <long, long>(c.mem); reg = c.reg; rbase = c.rbase; pc = c.pc; InitInstructionSet(); instructionsExecuted = c.instructionsExecuted; }
static void PartB() { List <long> input = ReadInput(); IntComputer a = new IntComputer(input, 2); a.Execute(); Console.WriteLine(); Console.WriteLine("Part B: Result is {0}", a.reg); }
static void Main(string[] args) { Sequence = GetContent(); var IntComputer = new IntComputer(Sequence); IntComputer.ProcessSequence(5); Console.ReadLine(); }
public async Task Input() { var(input, output) = Channels(); var computer = new IntComputer(input.Reader, output.Writer); await input.Writer.WriteAsync(1); var x = await computer.RunProgram(new[] { 3L, 0, 99 }); Assert.Equal(1, x[0]); }
static void PartB() { List <long> input = ReadInput(); IntComputer a = new IntComputer(input, 0); a.paintedPos[new Position(0, 0)] = 1; a.Execute(); Console.WriteLine("Part B: Result is:"); a.PrintPanel(); }
public async Task Output() { var(input, output) = Channels(); var computer = new IntComputer(input.Reader, output.Writer); await computer.RunProgram(new[] { 4L, 1, 99 }); var x = await output.Reader.ReadAsync(); Assert.Equal(1, x); }
static void PartA() { List <long> input = ReadInput(); IntComputer a = new IntComputer(input, 0); a.Execute(); int res = a.paintedPos.Where(x => x.Value == 2).Count(); Console.WriteLine("Part A: Result is {0}", res); }
static void PartB() { List <long> input = ReadInput(); IntComputer a = new IntComputer(input, 0); a.mem[0] = 2; a.Execute(); Console.SetCursorPosition(0, Console.CursorTop + 1); Console.WriteLine("Part B: Result is {0}", a.reg); }