-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday9_task1.py
More file actions
35 lines (26 loc) · 1.04 KB
/
Copy pathday9_task1.py
File metadata and controls
35 lines (26 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
###############################################################################
# Day 9, Task 1 #
###############################################################################
import aoc_util
day = 9
data_str = """2199943210
3987894921
9856789892
8767896789
9899965678"""
def task(data_set: list[str]) -> int:
height_map = []
for i in data_set:
height_map.append([int(x) for x in i.replace("\n", "")])
risk = 0
for row in range(len(height_map)):
for col in range(len(height_map[0])):
val = height_map[row][col]
if (row == 0 or height_map[row - 1][col] > val) \
and (row == len(height_map) - 1 or height_map[row + 1][col] > val) \
and (col == 0 or height_map[row][col - 1] > val) \
and (col == len(height_map[0]) - 1 or height_map[row][col + 1] > val):
risk += val + 1
return risk
aoc_util.run_with_data_str(task, data_str)
aoc_util.run_with_data_set(task, day)