aoc2021/d09/d09_1.py

26 lines
465 B
Python

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)
def printgrid():
for row in L:
print("".join(map(str,row)))
printgrid()
S = 0
for x in range(1,H-1):
for y in range(1,W-1):
p = L[x][y]
n = L[x-1][y]
s = L[x+1][y]
e = L[x][y-1]
w = L[x][y+1]
islow =all([p<n,p<s,p<e,p<w])
print(x,y,p,n,s,e,w)
if islow:
print(x,y,p, "is low")
S+= p+1
print(S)