aoc2021/d09/d09_1.py

12 lines
295 B
Python
Raw Permalink Normal View History

2021-12-09 22:55:58 +00:00
import sys
L = list(map(lambda s: [9]+list(map(int, s))+[9] ,sys.stdin.read().splitlines()))
W = len(L[0])
L = [[9]*W] + L + [[9]*W]
H = len(L)
S = 0
for x in range(1,H-1):
for y in range(1,W-1):
p = L[x][y]
2021-12-10 00:10:15 +00:00
S += (p+1) * all(p<L[x+i][y+j] for (i,j) in [(0,1),(1,0),(-1,0),(0,-1)])
2021-12-09 22:55:58 +00:00
print(S)