aoc2021/9/a.py

42 lines
710 B
Python

zone = {}
# with open("sample.txt") as f:
with open("input.txt") as f:
y = 0
for line in f.readlines():
x = 0
for char in line.strip():
zone[(x, y, )] = int(char)
x += 1
y += 1
width, height = x, y
print(width, height)
# print(zone)
lows = []
for i, ((x, y), value) in enumerate(zone.items()):
# print(i)
# left
if x > 0 and zone[(x-1, y)] <= value:
continue
# right
if x < width-1 and zone[(x+1, y)] <= value:
continue
# up
if y > 0 and zone[(x, y-1)] <= value:
continue
# down
if y < height-1 and zone[(x, y+1)] <= value:
continue
lows.append(value+1)
print(sum(lows))