Day 09
This commit is contained in:
17
day09/part2.py
Normal file
17
day09/part2.py
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/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:]))
|
||||
Reference in New Issue
Block a user