public override string Part2(string input) { var ic = new IntCode(input); ic.SetMemory(0, 2); var blocks = new HashSet <Point>(); var paddle = 0; var score = 0; var ball = 0; try { while (true) { var x = (int)ic.RunToOutput(); var y = (int)ic.RunToOutput(); var op = (int)ic.RunToOutput(); switch (op) { case 0: blocks.Remove(new Point(x, y)); break; case 2: blocks.Add(new Point(x, y)); break; case 3: paddle = x; break; case 4: ball = x; break; default: score = op; break; } if (ball < paddle) { ic.SetInput(-1); } else if (ball > paddle) { ic.SetInput(1); } else { ic.SetInput(0); } } } catch (HaltException) { return(score.ToString()); } }
public override string Part1(string input) { var painted = new HashSet <Point>(); var point = new Point(0, 0); var direction = new Point(0, -1); var ic = new IntCode(input); try { while (true) { var color = white.Contains(point) ? 1 : 0; ic.SetInput(color); if (ic.RunToOutput() == 1) { white.Add(point); } else { white.Remove(point); } painted.Add(point); if (ic.RunToOutput() == 1) { direction = direction.RotateRight(); } else { direction = direction.RotateLeft(); } point = point.Plus(direction); } } catch (HaltException) { return(painted.Count().ToString()); } throw new InvalidOperationException(); }