advent2021/nine_first.py

19 lines
476 B
Python
Executable File

#!/usr/bin/env python3
from useful import *
def parseline(s):
return [int(c) for c in s]
with open(0) as f:
basegrid = np.asarray([parseline(l) for l in lines(f)])
ic(basegrid)
w, h = basegrid.shape
grid = np.pad(basegrid, (1,1), constant_values=10)
ic(grid)
lowest = np.prod([grid[1:w+1,1:h+1] < grid[x:w+x,y:h+y] # bool prod = "all"
for (x, y) in ((2, 1), (1, 2), (0, 1), (1, 0))], axis=0)
print(np.sum((basegrid + 1) * lowest))