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] == '^')
|
if (grid[current.x][current.y] == '^')
|
||||||
{
|
{
|
||||||
splittersHit++;
|
splittersHit++;
|
||||||
var nextLeft = (current.x, current.y - 1);
|
CheckAndEnqueueIfNotVisited((current.x, current.y - 1));
|
||||||
var nextRight = (current.x, current.y + 1);
|
CheckAndEnqueueIfNotVisited((current.x, current.y + 1));
|
||||||
if (visited.Add(nextLeft)) seen.Enqueue(nextLeft);
|
|
||||||
if (visited.Add(nextRight)) seen.Enqueue(nextRight);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var next = (current.x + 1, current.y);
|
CheckAndEnqueueIfNotVisited((current.x + 1, current.y));
|
||||||
if (visited.Add(next)) seen.Enqueue(next);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return splittersHit;
|
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)
|
private Dictionary<Coordinate, long> GetNodesTraversedWitTimelineCount(string[] grid, Coordinate current, HashSet<Coordinate> path, Dictionary<Coordinate, long> nodeCountVisited)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue