generated from public/aoc_template
42 lines
1.0 KiB
Python
42 lines
1.0 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 = [
|
|
[
|
|
(13, "input4_test"),
|
|
(1376, "input4"),
|
|
],
|
|
[
|
|
(43, "input4_test"),
|
|
(8587, "input4"),
|
|
]
|
|
]
|
|
|
|
def parse_input(self) -> Grid:
|
|
return Grid.from_data(self.getInput(), translate={'@': True, '.': False})
|
|
|
|
def get_accessible_rolls(self, grid: Grid) -> list[Coordinate]:
|
|
return [roll for roll in grid.getActiveCells() if grid.getNeighbourSum(roll) < 4]
|
|
|
|
def part1(self) -> Any:
|
|
return len(self.get_accessible_rolls(self.parse_input()))
|
|
|
|
def part2(self) -> Any:
|
|
grid = self.parse_input()
|
|
ans = 0
|
|
while rolls := self.get_accessible_rolls(grid):
|
|
ans += len(rolls)
|
|
for roll in rolls:
|
|
grid.toggle(roll)
|
|
|
|
return ans
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(2025, 4)
|
|
day.run(verbose=True)
|