From 3d305d80bf4deb2d798948285101c9064b7104fa Mon Sep 17 00:00:00 2001 From: Sebastian Lindemeier Date: Thu, 11 Dec 2025 08:55:02 +0100 Subject: [PATCH] Refactor Day11 to handle missing paths in `paths` dictionary and improve variable usage readability --- AoC_2025/Day11.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/AoC_2025/Day11.cs b/AoC_2025/Day11.cs index 2df206e..8cd75e5 100644 --- a/AoC_2025/Day11.cs +++ b/AoC_2025/Day11.cs @@ -39,9 +39,10 @@ public class Day11 : IPuzzleSolver { if (from == to) return 1; if (memory.TryGetValue((from, to), out var res)) return res; + if (!paths.TryGetValue(from, out var pathsToCheck)) return 0; var totalAmount = 0L; - foreach (var path in paths[from]) + foreach (var path in pathsToCheck) { var amount = GetAmountPaths(path, to, paths, memory); memory[(path, to)] = amount; @@ -59,9 +60,10 @@ public class Day11 : IPuzzleSolver through.Remove(from); if (from == to) return through.Count == 0 ? 1 : 0; if (memory.TryGetValue((from, to), out var res) && res.Item2.SetEquals(through)) return res.Item1; + if (!paths.TryGetValue(from, out var pathsToCheck)) return 0; var totalAmount = 0L; - foreach (var path in paths[from]) + foreach (var path in pathsToCheck) { var amount = GetAmountPathsThrough(path, to, [..through], paths, memory); memory[(path, to)] = (amount, through);