aoc2021/day25.py
Stefan Harmuth d308a1df4d day25
2021-12-25 06:49:49 +01:00

61 lines
1.8 KiB
Python

from tools.aoc import AOCDay
from typing import Any
from tools.coordinate import Coordinate
from tools.grid import Grid
class Day(AOCDay):
test_solutions_p1 = [58, 351]
test_solutions_p2 = []
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."