private static Dictionary <Point, HullColor> PaintHull(long[] input, HullColor?initial = null) { var panels = new Dictionary <Point, HullColor>(); var c = new LongCodeComputer(input); var position = new Point(); var heading = Direction.Up; if (initial.HasValue) { panels[Point.Empty] = initial.Value; } while (true) { var currentPanel = panels.GetValueOrDefault(position, HullColor.Black); if (!c.RunWith((long)currentPanel, 2)) { break; } panels[position] = (HullColor)c.Outputs.Dequeue(); heading = c.Outputs.Dequeue() == 0 ? heading.TurnCounterClockwise() : heading.TurnClockwise(); position = position.MoveTo(heading); } return(panels); }
public void InputOutputWorks_WithCall() { var computer = new LongCodeComputer(new long[] { 3, 0, 4, 0, 99 }); var result = computer.RunWith(37); Assert.AreEqual(37, result); }
static void Main() { var input = File.ReadAllText("../../../input.txt").ParseLongs(); var sw = new Stopwatch(); sw.Start(); var c = new LongCodeComputer(input); var result = c.RunWith(1); Console.WriteLine($"Part 1: {result}"); c = new LongCodeComputer(input); result = c.RunWith(2); Console.WriteLine($"Part 2: {result}"); Console.WriteLine($"After {c.StepCount} steps."); sw.Stop(); Console.WriteLine($"Solving took {sw.ElapsedMilliseconds}ms."); _ = Console.ReadLine(); }