-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
day_25.py
70 lines (57 loc) · 1.45 KB
/
day_25.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import aoc_helper
from aoc_helper import (
decode_text,
extract_ints,
frange,
irange,
iter,
list,
map,
range,
tail_call,
)
raw = aoc_helper.fetch(25, 2021)
# raw = """v...>>.vv>
# .vv>>.vv..
# >>.>v>...v
# >>v>>.>.v.
# v>v.vv.v..
# >.>>..v...
# .vv..>.>v.
# v.v..>>v.v
# ....v..v.>"""
def parse_raw():
return map(list, raw.splitlines()).collect()
data = parse_raw()
def step(map: list[list[str]]):
moved = 0
will_step = []
for y, row in map.enumerated():
for x, (from_, to) in enumerate(zip(row[-1:] + row[:-1], row), start=-1):
if to == "." and from_ == ">":
will_step.append((x, y))
for x, y in will_step:
map[y][x] = "."
map[y][x + 1] = ">"
moved += len(will_step)
will_step.clear()
for y, (from_, to) in enumerate(zip(map[-1:] + map[:-1], map), start=-1):
for x, (from_cell, to_cell) in enumerate(zip(from_, to)):
if to_cell == "." and from_cell == "v":
will_step.append((x, y))
for x, y in will_step:
map[y][x] = "."
map[y + 1][x] = "v"
moved += len(will_step)
return moved
def part_one():
i = 1
map = data.deepcopy()
while step(map):
i += 1
# print(i, "\n" + "\n".join("".join(row) for row in map))
return i
def part_two():
...
aoc_helper.lazy_submit(day=25, year=2021, solution=part_one)
aoc_helper.lazy_submit(day=25, year=2021, solution=part_two)