Refactor Day07 to rename variables for clarity in timeline count recursion logic

This commit is contained in:
Sebastian Lindemeier 2025-12-08 10:31:15 +01:00
parent 14e4a8dfe9
commit 249e092494
1 changed files with 7 additions and 7 deletions

View File

@ -77,24 +77,24 @@ public class Day07 : IPuzzleSolver<long>
} }
// Dictionary only for memoization // Dictionary only for memoization
private long GetTimelinesCountRecursive(string[] grid, Coordinate current, Dictionary<Coordinate, long> nodeCountVisited) private long GetTimelinesCountRecursive(string[] grid, Coordinate current, Dictionary<Coordinate, long> memory)
{ {
if (current.x >= grid.Length) if (current.x >= grid.Length)
{ {
return 1; return 1;
} }
if(nodeCountVisited.TryGetValue(current, out var count)) return count; if(memory.TryGetValue(current, out var count)) return count;
if (grid[current.x][current.y] == '^') if (grid[current.x][current.y] == '^')
{ {
var resLeft = GetTimelinesCountRecursive(grid, (current.x, current.y - 1), nodeCountVisited); var resLeft = GetTimelinesCountRecursive(grid, (current.x, current.y - 1), memory);
var resRight = GetTimelinesCountRecursive(grid, (current.x, current.y + 1), nodeCountVisited); var resRight = GetTimelinesCountRecursive(grid, (current.x, current.y + 1), memory);
nodeCountVisited[current] = resLeft + resRight; memory[current] = resLeft + resRight;
return resLeft + resRight; return resLeft + resRight;
} }
var res = GetTimelinesCountRecursive(grid, (current.x + 1, current.y), nodeCountVisited); var res = GetTimelinesCountRecursive(grid, (current.x + 1, current.y), memory);
nodeCountVisited[current] = res; memory[current] = res;
return res; return res;
} }