From 62f46aff7d26b0ea30c2fbae74afab17a0bb3e3f Mon Sep 17 00:00:00 2001 From: Sebastian Lindemeier Date: Sun, 7 Dec 2025 17:51:57 +0100 Subject: [PATCH] Refactor Day07 to extract node visited count update logic --- AoC_2025/Day07.cs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/AoC_2025/Day07.cs b/AoC_2025/Day07.cs index 5d20e9d..1cee95a 100644 --- a/AoC_2025/Day07.cs +++ b/AoC_2025/Day07.cs @@ -71,12 +71,7 @@ public class Day07 : IPuzzleSolver { 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 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 UpdateNodeVisitedCounts(Coordinate current, HashSet path, Dictionary nodeCountVisited) + { + var addAmount = nodeCountVisited.GetValueOrDefault(current, 1); + foreach (var node in path) { - var res = GetNodesTraversedWitTimelineCount(grid, (current.x + 1, current.y), [..path], nodeCountVisited); - return res; + nodeCountVisited[node] += addAmount; } + + return nodeCountVisited; } } \ No newline at end of file