Day 9.
This commit is contained in:
44
2021/9/main.py
Normal file
44
2021/9/main.py
Normal file
@@ -0,0 +1,44 @@
|
||||
data = []
|
||||
|
||||
with open('data', 'r') as fp:
|
||||
# NOTE(dev): We assume all lines are the same length
|
||||
for line in fp:
|
||||
data_line = []
|
||||
for ch in line.strip():
|
||||
data_line.append(int(ch))
|
||||
data.append(data_line)
|
||||
|
||||
total = 0
|
||||
for y in range(0, len(data)):
|
||||
for x in range(0, len(data[y])):
|
||||
sub_total = 0
|
||||
all_four = 0
|
||||
# above
|
||||
if(y > 0):
|
||||
if(data[y-1][x] > data[y][x]):
|
||||
all_four += 1
|
||||
else:
|
||||
all_four += 1 # skip
|
||||
# below
|
||||
if(y < len(data) - 1):
|
||||
if(data[y+1][x] > data[y][x]):
|
||||
all_four += 1
|
||||
else:
|
||||
all_four += 1 #skip
|
||||
# left
|
||||
if(x > 0):
|
||||
if(data[y][x-1] > data[y][x]):
|
||||
all_four += 1
|
||||
else:
|
||||
all_four += 1 #skip
|
||||
# right
|
||||
if(x < len(data[y]) - 1):
|
||||
if(data[y][x+1] > data[y][x]):
|
||||
all_four += 1
|
||||
else:
|
||||
all_four += 1 #skip
|
||||
|
||||
if(all_four == 4):
|
||||
total += data[y][x] + 1
|
||||
|
||||
print(total)
|
||||
Reference in New Issue
Block a user