generated from public/aoc_template
51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
from tools.aoc import AOCDay
|
|
from tools.coordinate import Coordinate
|
|
from tools.grid import Grid
|
|
from typing import Any
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(21, "input7_test"),
|
|
(1703, "input7"),
|
|
],
|
|
[
|
|
(40, "input7_test"),
|
|
(171692855075500, "input7"),
|
|
]
|
|
]
|
|
|
|
def get_timeline_count(self, start: Coordinate, grid: Grid) -> int:
|
|
if not grid.isWithinBoundaries(start):
|
|
return 1
|
|
|
|
while not grid.get(start) and grid.isWithinBoundaries(start):
|
|
start += (0, 1)
|
|
|
|
if not grid.isWithinBoundaries(start):
|
|
return 1
|
|
else:
|
|
if start in self.DP:
|
|
return self.DP[start]
|
|
|
|
self.SEEN.add(start)
|
|
|
|
ans = self.get_timeline_count(start + (-1, 0), grid) + self.get_timeline_count(start + (1, 0), grid)
|
|
self.DP[start] = ans
|
|
return ans
|
|
|
|
def part1(self) -> Any:
|
|
grid = Grid.from_data(self.getInput(), translate={'.': False, '^': True})
|
|
self.get_timeline_count(list(grid.find('S'))[0], grid)
|
|
return len(self.SEEN)
|
|
|
|
def part2(self) -> Any:
|
|
grid = Grid.from_data(self.getInput(), translate={'.': False, '^': True})
|
|
return self.get_timeline_count(list(grid.find('S'))[0], grid)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(2025, 7)
|
|
day.run(verbose=True)
|