65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
from tools.aoc import AOCDay
|
|
from typing import Any
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(21, "input8_test"),
|
|
(1854, "input8_dennis"),
|
|
(1679, "input8"),
|
|
],
|
|
[
|
|
(8, "input8_test"),
|
|
(527340, "input8_dennis"),
|
|
(536625, "input8"),
|
|
]
|
|
]
|
|
|
|
def get_vision(self, part2: bool = False):
|
|
trees = [list(map(int, l)) for l in self.getInput()]
|
|
len_x = len(trees[0])
|
|
len_y = len(trees)
|
|
visible = set()
|
|
max_scenic = 0
|
|
|
|
dirs = [(-1, 0), (1, 0), (0, -1), (0, 1)]
|
|
|
|
for x in range(len_x):
|
|
for y in range(len_y):
|
|
scenic_score = 1
|
|
for d in dirs:
|
|
vx, vy = x + d[0], y + d[1]
|
|
view = 0
|
|
while 0 <= vx < len_x and 0 <= vy < len_y:
|
|
view += 1
|
|
if trees[vy][vx] >= trees[y][x]:
|
|
break
|
|
|
|
vx += d[0]
|
|
vy += d[1]
|
|
else:
|
|
visible.add((x, y))
|
|
|
|
scenic_score *= view
|
|
|
|
if scenic_score > max_scenic:
|
|
max_scenic = scenic_score
|
|
|
|
if part2:
|
|
return max_scenic
|
|
else:
|
|
return len(visible)
|
|
|
|
|
|
def part1(self) -> Any:
|
|
return self.get_vision()
|
|
|
|
def part2(self) -> Any:
|
|
return self.get_vision(True)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(2022, 8)
|
|
day.run(verbose=True)
|