Skip to content

Commit 4a479c1

Browse files
committed
Implement 2024 day 25
1 parent b415719 commit 4a479c1

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

2024/src/aoc/days/day25.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import numpy
2+
3+
from . import CombinedRunner
4+
5+
6+
class DayRunner(CombinedRunner):
7+
@classmethod
8+
def run_both(cls, input: str) -> tuple[int, None]:
9+
blocks = input.strip().split("\n\n")
10+
11+
keys = []
12+
locks = []
13+
14+
for block in blocks:
15+
grid = numpy.array(list(map(list, block.splitlines())))
16+
heights = numpy.count_nonzero(grid == "#", axis=0)
17+
18+
if block.startswith("#####"):
19+
locks.append(heights)
20+
else:
21+
keys.append(heights)
22+
23+
fitting = 0
24+
25+
for key in keys:
26+
for lock in locks:
27+
if numpy.all((key + lock) <= 7):
28+
fitting += 1
29+
30+
return fitting, None

2024/tests/samples/25.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
#####

2024/tests/test_day25.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from aoc.days.day25 import DayRunner
2+
3+
from . import get_data
4+
5+
6+
def test_sample_part1() -> None:
7+
assert DayRunner.part1(get_data(25)) == 3

0 commit comments

Comments
 (0)