18 lines
561 B
Python
18 lines
561 B
Python
#!/usr/bin/env python3
|
|
import operator
|
|
from functools import reduce
|
|
import numpy as np
|
|
from skimage.segmentation import flood_fill
|
|
|
|
|
|
arr = np.array([[int(n) for n in line.strip()] for line in open("input.txt")])
|
|
|
|
borders = np.zeros_like(arr)
|
|
borders[arr == 9] = 1
|
|
curr_sum = np.sum(borders)
|
|
areas = []
|
|
while np.shape(nxt := np.array(np.where(borders == 0))) != (2, 0):
|
|
borders = flood_fill(borders, tuple(nxt[:, 0]), 1, tolerance=0, connectivity=1)
|
|
areas.append(-curr_sum + (curr_sum := np.sum(borders)))
|
|
print(reduce(operator.mul, sorted(areas)[-3:]))
|