This commit is contained in:
parent
1e2db73b52
commit
0acb51ca97
@ -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
@ -0,0 +1,39 @@
|
||||
#####
|
||||
.####
|
||||
.####
|
||||
.####
|
||||
.#.#.
|
||||
.#...
|
||||
.....
|
||||
|
||||
#####
|
||||
##.##
|
||||
.#.##
|
||||
...##
|
||||
...#.
|
||||
...#.
|
||||
.....
|
||||
|
||||
.....
|
||||
#....
|
||||
#....
|
||||
#...#
|
||||
#.#.#
|
||||
#.###
|
||||
#####
|
||||
|
||||
.....
|
||||
.....
|
||||
#.#..
|
||||
###..
|
||||
###.#
|
||||
###.#
|
||||
#####
|
||||
|
||||
.....
|
||||
.....
|
||||
.....
|
||||
#....
|
||||
#.#..
|
||||
#.#.#
|
||||
#####
|
Loading…
Reference in New Issue
Block a user