Skip to main content

Module day09

Module day09 

Source
Expand description

§Smoke Basin

Part two is the classic flood fill algorithm with a twist to return the size of the filled area. This algorithm can be implemented either as a DFS using recursion or as a BFS using an auxiliary data structure such as a VecDeque.

This solution uses a DFS approach as it’s faster and Rust’s stack size limit seems enough to accommodate the maximum basin size. Note that when masked, newline can be treated the same as '9' for a natural barrier that eliminates bounds checking. The Grid and Point modules make it easy to perform a flood fill that tracks the lowest value seen along the way, to share the work between part one and part two.

Structs§

Basin

Functions§

flood_fill 🔒
parse
part1
part2