public void DrawWire(Wire wire, WirePath path) { foreach (var point in path.Walk(CentralPort)) { if (!_cells.TryGetValue(point, out var cell)) { cell = new GridCell(); _cells.Add(point, cell); } cell.CrossedBy(wire); } }
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.WhatIsTheShortestDistanceToCentralPortFromTheClosestIntersection()); }