-
Notifications
You must be signed in to change notification settings - Fork 0
/
day9.py
33 lines (25 loc) · 904 Bytes
/
day9.py
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
from common.algebra import Point, Matrix
from common.day import Day
class Heightmap(Matrix):
def get_low_points(self) -> set[Point]:
low_points = set()
for x in self.content:
for y in range(len(self.content[x])):
point = self.get(x, y)
neighbours = self.get_neighbours(x, y)
if point < min(neighbours):
low_points.add(point)
self.logger.debug(low_points)
return low_points
class Day9(Day):
def __init__(self, input_file_name: str):
super().__init__(input_file_name)
self.matrix = Heightmap().from_raw_input(self.read_input_lines())
def part1(self) -> int:
low_points = self.matrix.get_low_points()
result = 0
for p in low_points:
result += p.value + 1
return result
def part2(self) -> int:
return -1