speed up 2024 day 6 pt 2 a bit
limiting the candidates for new obstacle positions to positions the guard can reach cuts part 2 runtime from ~47s to ~10s
This commit is contained in:
parent
db20c89051
commit
951f6c51b8
1 changed files with 6 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue