2024 day 25.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Mikaël Capelle 2024-12-25 10:16:27 +01:00
parent 1e2db73b52
commit 0acb51ca97
3 changed files with 4072 additions and 1 deletions

View File

@ -1,7 +1,40 @@
import itertools as it
from typing import Any, Iterator
from ..base import BaseSolver
def read_locks_and_keys(input: str):
locks: list[tuple[int, ...]] = []
keys: list[tuple[int, ...]] = []
for block in map(str.splitlines, input.split("\n\n")):
n_rows, n_cols = len(block), len(block[0])
if block[0] == "#" * n_cols:
locks.append(
tuple(
next(i for i in range(n_rows) if block[i][j] == ".") - 1
for j in range(n_cols)
)
)
else:
keys.append(
tuple(
n_rows - next(i for i in range(n_rows) if block[i][j] == "#") - 1
for j in range(n_cols)
)
)
return locks, keys
class Solver(BaseSolver):
def solve(self, input: str) -> Iterator[Any]: ...
def solve(self, input: str) -> Iterator[Any]:
locks, keys = read_locks_and_keys(input)
assert len(set(locks)) == len(locks)
assert len(set(keys)) == len(keys)
yield sum(
all(c1 + c2 <= 5 for c1, c2 in zip(lock, key, strict=True))
for lock, key in it.product(locks, keys)
)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,39 @@
#####
.####
.####
.####
.#.#.
.#...
.....
#####
##.##
.#.##
...##
...#.
...#.
.....
.....
#....
#....
#...#
#.#.#
#.###
#####
.....
.....
#.#..
###..
###.#
###.#
#####
.....
.....
.....
#....
#.#..
#.#.#
#####