mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Implement 2024 day 25
This commit is contained in:
30
2024/src/aoc/days/day25.py
Normal file
30
2024/src/aoc/days/day25.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import numpy
|
||||||
|
|
||||||
|
from . import CombinedRunner
|
||||||
|
|
||||||
|
|
||||||
|
class DayRunner(CombinedRunner):
|
||||||
|
@classmethod
|
||||||
|
def run_both(cls, input: str) -> tuple[int, None]:
|
||||||
|
blocks = input.strip().split("\n\n")
|
||||||
|
|
||||||
|
keys = []
|
||||||
|
locks = []
|
||||||
|
|
||||||
|
for block in blocks:
|
||||||
|
grid = numpy.array(list(map(list, block.splitlines())))
|
||||||
|
heights = numpy.count_nonzero(grid == "#", axis=0)
|
||||||
|
|
||||||
|
if block.startswith("#####"):
|
||||||
|
locks.append(heights)
|
||||||
|
else:
|
||||||
|
keys.append(heights)
|
||||||
|
|
||||||
|
fitting = 0
|
||||||
|
|
||||||
|
for key in keys:
|
||||||
|
for lock in locks:
|
||||||
|
if numpy.all((key + lock) <= 7):
|
||||||
|
fitting += 1
|
||||||
|
|
||||||
|
return fitting, None
|
||||||
39
2024/tests/samples/25.txt
Normal file
39
2024/tests/samples/25.txt
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#####
|
||||||
|
.####
|
||||||
|
.####
|
||||||
|
.####
|
||||||
|
.#.#.
|
||||||
|
.#...
|
||||||
|
.....
|
||||||
|
|
||||||
|
#####
|
||||||
|
##.##
|
||||||
|
.#.##
|
||||||
|
...##
|
||||||
|
...#.
|
||||||
|
...#.
|
||||||
|
.....
|
||||||
|
|
||||||
|
.....
|
||||||
|
#....
|
||||||
|
#....
|
||||||
|
#...#
|
||||||
|
#.#.#
|
||||||
|
#.###
|
||||||
|
#####
|
||||||
|
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
#.#..
|
||||||
|
###..
|
||||||
|
###.#
|
||||||
|
###.#
|
||||||
|
#####
|
||||||
|
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
#....
|
||||||
|
#.#..
|
||||||
|
#.#.#
|
||||||
|
#####
|
||||||
7
2024/tests/test_day25.py
Normal file
7
2024/tests/test_day25.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from aoc.days.day25 import DayRunner
|
||||||
|
|
||||||
|
from . import get_data
|
||||||
|
|
||||||
|
|
||||||
|
def test_sample_part1() -> None:
|
||||||
|
assert DayRunner.part1(get_data(25)) == 3
|
||||||
Reference in New Issue
Block a user