Refactor Day07 to extract node visited count update logic
This commit is contained in:
parent
f0ac76df15
commit
62f46aff7d
|
|
@ -71,12 +71,7 @@ public class Day07 : IPuzzleSolver<long>
|
|||
{
|
||||
if (current.x >= grid.Length || nodeCountVisited.ContainsKey(current))
|
||||
{
|
||||
var addAmount = nodeCountVisited.GetValueOrDefault(current, 1);
|
||||
foreach (var node in path)
|
||||
{
|
||||
nodeCountVisited[node] += addAmount;
|
||||
}
|
||||
|
||||
nodeCountVisited = UpdateNodeVisitedCounts(current, path, nodeCountVisited);
|
||||
return nodeCountVisited;
|
||||
}
|
||||
|
||||
|
|
@ -89,10 +84,19 @@ public class Day07 : IPuzzleSolver<long>
|
|||
var resRight = GetNodesTraversedWitTimelineCount(grid, (current.x, current.y + 1), [..path], resLeft);
|
||||
return resRight;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var res = GetNodesTraversedWitTimelineCount(grid, (current.x + 1, current.y), [..path], nodeCountVisited);
|
||||
return res;
|
||||
}
|
||||
|
||||
private static Dictionary<Coordinate, long> UpdateNodeVisitedCounts(Coordinate current, HashSet<Coordinate> path, Dictionary<Coordinate, long> nodeCountVisited)
|
||||
{
|
||||
var addAmount = nodeCountVisited.GetValueOrDefault(current, 1);
|
||||
foreach (var node in path)
|
||||
{
|
||||
nodeCountVisited[node] += addAmount;
|
||||
}
|
||||
|
||||
return nodeCountVisited;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue