Refactor Day07 to rename variables for clarity in timeline count recursion logic
This commit is contained in:
parent
14e4a8dfe9
commit
249e092494
|
|
@ -77,24 +77,24 @@ public class Day07 : IPuzzleSolver<long>
|
|||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
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] == '^')
|
||||
{
|
||||
var resLeft = GetTimelinesCountRecursive(grid, (current.x, current.y - 1), nodeCountVisited);
|
||||
var resRight = GetTimelinesCountRecursive(grid, (current.x, current.y + 1), nodeCountVisited);
|
||||
nodeCountVisited[current] = resLeft + resRight;
|
||||
var resLeft = GetTimelinesCountRecursive(grid, (current.x, current.y - 1), memory);
|
||||
var resRight = GetTimelinesCountRecursive(grid, (current.x, current.y + 1), memory);
|
||||
memory[current] = resLeft + resRight;
|
||||
return resLeft + resRight;
|
||||
}
|
||||
|
||||
var res = GetTimelinesCountRecursive(grid, (current.x + 1, current.y), nodeCountVisited);
|
||||
nodeCountVisited[current] = res;
|
||||
var res = GetTimelinesCountRecursive(grid, (current.x + 1, current.y), memory);
|
||||
memory[current] = res;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue