Refactor Day07 to extract common coordinate enqueue logic
This commit is contained in:
parent
629467f376
commit
92ef64fd88
|
|
@ -59,19 +59,21 @@ public class Day07 : IPuzzleSolver<long>
|
|||
if (grid[current.x][current.y] == '^')
|
||||
{
|
||||
splittersHit++;
|
||||
var nextLeft = (current.x, current.y - 1);
|
||||
var nextRight = (current.x, current.y + 1);
|
||||
if (visited.Add(nextLeft)) seen.Enqueue(nextLeft);
|
||||
if (visited.Add(nextRight)) seen.Enqueue(nextRight);
|
||||
CheckAndEnqueueIfNotVisited((current.x, current.y - 1));
|
||||
CheckAndEnqueueIfNotVisited((current.x, current.y + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
var next = (current.x + 1, current.y);
|
||||
if (visited.Add(next)) seen.Enqueue(next);
|
||||
CheckAndEnqueueIfNotVisited((current.x + 1, current.y));
|
||||
}
|
||||
}
|
||||
|
||||
return splittersHit;
|
||||
|
||||
void CheckAndEnqueueIfNotVisited(Coordinate coordinate)
|
||||
{
|
||||
if (visited.Add(coordinate)) seen.Enqueue(coordinate);
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<Coordinate, long> GetNodesTraversedWitTimelineCount(string[] grid, Coordinate current, HashSet<Coordinate> path, Dictionary<Coordinate, long> nodeCountVisited)
|
||||
|
|
|
|||
Loading…
Reference in New Issue