Skip to content

Commit 2d1893b

Browse files
committed
Finished AoC 2021!
1 parent 20fcd14 commit 2d1893b

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

day25/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Part 1
2+
<PART_1_TEXT>
3+
4+
### Part 2
5+
<PART_2_TEXT>

day25/__init__.py

Whitespace-only changes.

day25/solution.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""
2+
"""
3+
4+
from utils import Solution
5+
from typing import Any
6+
import numpy as np
7+
8+
9+
class DaySolution(Solution):
10+
def __init__(self, day: int = 25, year: int = 2021) -> None:
11+
super().__init__(day, year)
12+
13+
def _parse_data(self, input_data: str) -> Any:
14+
"""
15+
"""
16+
c_to_int = {'.': 0, '>': 1, 'v': 2}
17+
seac_map = np.array([[c_to_int[x] for x in line] for line in input_data.strip().split("\n")])
18+
return seac_map
19+
20+
def _solve_part1(self, parsed_data: Any) -> Any:
21+
"""
22+
"""
23+
nr_turns = 0
24+
cur_map = parsed_data.copy()
25+
map_shape = cur_map.shape
26+
while True:
27+
new_map = cur_map.copy()
28+
nr_turns += 1
29+
e_c_row, e_c_col = np.where(cur_map == 1)
30+
to_move = []
31+
for p in zip(e_c_row, e_c_col):
32+
to_col = (p[1] + 1) % map_shape[1]
33+
if cur_map[p[0], to_col] == 0:
34+
to_move.append([p, to_col])
35+
for m_p in to_move:
36+
new_map[m_p[0][0], m_p[1]] = 1
37+
new_map[m_p[0][0], m_p[0][1]] = 0
38+
s_c_row, s_c_col = np.where(cur_map == 2)
39+
to_move = []
40+
for p in zip(s_c_row, s_c_col):
41+
to_row = (p[0] + 1) % map_shape[0]
42+
if new_map[to_row, p[1]] == 0:
43+
to_move.append([p, to_row])
44+
for m_p in to_move:
45+
new_map[m_p[1], m_p[0][1]] = 2
46+
new_map[m_p[0][0], m_p[0][1]] = 0
47+
if (new_map == cur_map).all():
48+
break
49+
else:
50+
cur_map = new_map
51+
return nr_turns
52+
53+
def _solve_part2(self, parsed_data: Any) -> Any:
54+
"""
55+
"""
56+
return 1

test/test_day25.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
from day25.solution import DaySolution
3+
4+
5+
@pytest.fixture
6+
def day_testdata():
7+
return """\
8+
v...>>.vv>
9+
.vv>>.vv..
10+
>>.>v>...v
11+
>>v>>.>.v.
12+
v>v.vv.v..
13+
>.>>..v...
14+
.vv..>.>v.
15+
v.v..>>v.v
16+
....v..v.>\
17+
"""
18+
19+
20+
def test_part1(day_testdata):
21+
sol = DaySolution()
22+
parsed_data = sol._parse_data(day_testdata)
23+
result = sol._solve_part1(parsed_data)
24+
assert result == 58
25+
26+
27+
def test_part2(day_testdata):
28+
sol = DaySolution()
29+
parsed_data = sol._parse_data(day_testdata)
30+
result = sol._solve_part2(parsed_data)
31+
assert result == 1

0 commit comments

Comments
 (0)