static void Main(string[] args) { var grid = new Grid(); var wire = new Wire(1); foreach (var line in File.ReadAllLines(args[0])) { var path = WirePath.FromPathString(line); grid.DrawWire(wire, path); wire = wire.Next(); } Console.WriteLine(grid.WhatIsTheFewestCombinedStepsTheWiresMustTakeToReachAnIntersection()); }
public void DrawWire(Wire wire, WirePath path) { foreach (var move in path.Walk(CentralPort)) { Console.WriteLine("Wire{4}: step={0}, square={1}, first={2}, last={3}", move.Step, move.Square, move.FirstInstructionMove, move.LastInstructionMove, wire); if (!_cells.TryGetValue(move.Square, out var cell)) { cell = new GridCell(); _cells.Add(move.Square, cell); } cell.CrossedBy(wire, move.Step); } }