From b6db8e801d0cc3e83a1051418b04d618df01ee73 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 16 Dec 2024 18:29:49 +0000 Subject: [PATCH] Update docs on Mon Dec 16 18:29:49 UTC 2024 --- 2024/16/index.html | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/2024/16/index.html b/2024/16/index.html index 5a9d9a7d..4e0ca21e 100644 --- a/2024/16/index.html +++ b/2024/16/index.html @@ -301,7 +301,6 @@

Reindeer Maze

static readonly Complex South = Complex.ImaginaryOne; static readonly Complex West = -1; static readonly Complex East = 1; - static readonly Complex[] Dirs = { North, East, West, South }; public object PartOne(string input) => FindBestScore(GetMap(input)); public object PartTwo(string input) => FindBestSpots(GetMap(input)); @@ -330,12 +329,12 @@

Reindeer Maze

} Dictionary<State, int> Dijkstra(Map map, Complex goal) { - // Dijkstra algorithm; works backwards from the goal returns the - // distances to all tiles and directions. + // Dijkstra algorithm; works backwards from the goal, returns the + // distances to _all_ tiles and directions. var dist = new Dictionary<State, int>(); var q = new PriorityQueue<State, int>(); - foreach (var dir in Dirs) { + foreach (var dir in new[]{North, East, West, South}) { q.Enqueue((goal, dir), 0); dist[(goal, dir)] = 0; } @@ -357,7 +356,7 @@

Reindeer Maze

// in forward mode we scan the possible states from the start state towards the goal. // in backward mode we are working backwards from the goal to the start. IEnumerable<(State, int cost)> Steps(Map map, State state, bool forward) { - foreach (var dir in Dirs) { + foreach (var dir in new[]{North, East, West, South}) { if (dir == state.dir) { var pos = forward ? state.pos + dir : state.pos - dir; if (map.GetValueOrDefault(pos) != '#') { @@ -376,7 +375,7 @@

Reindeer Maze

return ( from y in Enumerable.Range(0, map.Length) from x in Enumerable.Range(0, map[0].Length) - select new KeyValuePair<Complex, char>(Complex.ImaginaryOne * y + x, map[y][x]) + select new KeyValuePair<Complex, char>(x + y * South, map[y][x]) ).ToDictionary(); } Complex Goal(Map map) => map.Keys.Single(k => map[k] == 'E');