AoC 2022 D24: Blizzard Basin
| Problem statement | Source code | Tags: BFS/DFS
← Previous Back to AoC Index Next →
Part 1
All it takes is to do a BFS with the current time as part of the state. Also realize that you don't have to actually simulate the blizzards; given the time and a position, you can know if a blizzard is there by going backwards in the direction of the blizzard and checking if there was a blizzard there at time 0.
The canMoveTo function essentially determines the edges for a node (r, c, t) by checking if the position is out of bounds, is a wall, or has a blizzard at time t. If not, we can move there.
Writing a BFS for the last time this year.
The answer is given by bfs board width height (0, 1, 0) (height + 1, width).
Part 2
Just execute the BFS three times: from start to end, then from end to start, and finally from start to end again. Each time, pass the previous end time as the starting time for the next BFS.