Skip to content
advent of code 2021

day 09

smoke basin

for part one, simply count the number of cells in which all neighbors are strictly greater.

for part two, floodfill until you have previously visited or until you find a height 9

python
def floodfill(grid, r, c):
    if grid[r][c] is None or grid[r][c] == 9: 
        return 0    
    s, grid[r][c] = 1, None
    for nr, nc in neighbors(grid, r, c):
        s += floodfill(grid, nr, nc)    
    return s