70 lines
1.9 KiB
Python
70 lines
1.9 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 = [
|
|
[
|
|
(58, "test_input25_1_0"),
|
|
(351, "input25")
|
|
],
|
|
[]
|
|
]
|
|
|
|
def part1(self) -> Any:
|
|
grid = Grid(' ')
|
|
for y, l in enumerate(self.getInput()):
|
|
for x, c in enumerate(l):
|
|
if c != '.':
|
|
grid.set(Coordinate(x, y), c)
|
|
|
|
step_count = 0
|
|
moved = True
|
|
while moved:
|
|
move_me = set()
|
|
moved = False
|
|
step_count += 1
|
|
|
|
for y in grid.rangeY():
|
|
for x in grid.rangeX():
|
|
source = Coordinate(x, y)
|
|
if grid.get(source) == '>':
|
|
if x + 1 > grid.maxX:
|
|
target = Coordinate(0, y)
|
|
else:
|
|
target = Coordinate(x + 1, y)
|
|
if grid.get(target) == ' ':
|
|
move_me.add((source, target))
|
|
|
|
for s, t in move_me:
|
|
moved = True
|
|
grid.flip(s, t)
|
|
|
|
move_me = set()
|
|
for x in grid.rangeX():
|
|
for y in grid.rangeY():
|
|
source = Coordinate(x, y)
|
|
if grid.get(source) == 'v':
|
|
if y + 1 > grid.maxY:
|
|
target = Coordinate(x, 0)
|
|
else:
|
|
target = Coordinate(x, y + 1)
|
|
if grid.get(target) == ' ':
|
|
move_me.add((source, target))
|
|
|
|
for s, t in move_me:
|
|
moved = True
|
|
grid.flip(s, t)
|
|
|
|
return step_count
|
|
|
|
def part2(self) -> Any:
|
|
return "No parr2 on the 25."
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(25)
|
|
day.run(verbose=True)
|