diff --git a/2024/lib/2024/6.ex b/2024/lib/2024/6.ex index 5b37556..4d05a4d 100644 --- a/2024/lib/2024/6.ex +++ b/2024/lib/2024/6.ex @@ -21,7 +21,12 @@ aoc 2024, 6 do in_front_of_guard = forward(state).pos - for pos <- Map.keys(state.grid), pos != in_front_of_guard, not blocked?(state, pos), reduce: 0 do + # by first simulating the regular board i can limit my search to just + # positions that are reachable. this cuts the runtime of pt 2 from about + # 47s to about 10s + %State{visited: visited} = simulate(state) + + for pos <- visited, pos != in_front_of_guard, not blocked?(state, pos), reduce: 0 do sum -> if (state |> insert_obstacle(pos)