diff --git a/2024/src/aoc/days/day25.py b/2024/src/aoc/days/day25.py new file mode 100644 index 0000000..a500a3e --- /dev/null +++ b/2024/src/aoc/days/day25.py @@ -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 diff --git a/2024/tests/samples/25.txt b/2024/tests/samples/25.txt new file mode 100644 index 0000000..8e29855 --- /dev/null +++ b/2024/tests/samples/25.txt @@ -0,0 +1,39 @@ +##### +.#### +.#### +.#### +.#.#. +.#... +..... + +##### +##.## +.#.## +...## +...#. +...#. +..... + +..... +#.... +#.... +#...# +#.#.# +#.### +##### + +..... +..... +#.#.. +###.. +###.# +###.# +##### + +..... +..... +..... +#.... +#.#.. +#.#.# +##### diff --git a/2024/tests/test_day25.py b/2024/tests/test_day25.py new file mode 100644 index 0000000..838d135 --- /dev/null +++ b/2024/tests/test_day25.py @@ -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