1 """Find where smoke settles"""
6 with open("9_input.txt") as f:
8 heights.append([int(char) for char in line.strip()])
11 n_cols = len(heights[0])
15 for i in range(n_rows):
16 for j in range(n_cols):
19 heights[i - 1][j] if i != 0 else 10,
20 heights[i][j - 1] if j != 0 else 10,
21 10 if i == n_rows - 1 else heights[i + 1][j],
22 10 if j == n_cols - 1 else heights[i][j + 1],
24 if val < min(to_compare):
26 mins_coords.append((i, j))
29 for minimum in mins_coords:
30 to_walk = set([minimum])
35 orth_coords = [(i - 1, j), (i, j - 1), (i + 1, j), (i, j + 1)]
36 for x, y in orth_coords:
38 if (x >= 0 and y >= 0 and heights[x][y] != 9 and
39 (x, y) not in walked):
48 basins = sorted(basins, key=lambda x: len(x))
49 print(math.prod([len(b) for b in basins[-3:]]))