Compare commits
No commits in common. "67a63a4d4d69dfc00e4d87392e448ab7fd4743c9" and "1278ebe7f04ae2134a8e177a41beec1c3952b80e" have entirely different histories.
67a63a4d4d
...
1278ebe7f0
4 changed files with 0 additions and 8047 deletions
|
|
@ -1,40 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import itertools
|
||||
import sys
|
||||
|
||||
Schematic = list[int]
|
||||
|
||||
|
||||
def solve(input: str) -> int:
|
||||
def parse_schematic(input: list[str]) -> Schematic:
|
||||
return [row.count("#") - 1 for row in list(zip(*input))]
|
||||
|
||||
def parse(input: str) -> tuple[list[Schematic], list[Schematic]]:
|
||||
locks: list[Schematic] = []
|
||||
keys: list[Schematic] = []
|
||||
|
||||
for schematic in input.strip().split("\n\n"):
|
||||
if schematic.startswith("#####"):
|
||||
locks.append(parse_schematic(schematic.splitlines()))
|
||||
elif schematic.endswith("#####"):
|
||||
keys.append(parse_schematic(schematic.splitlines()[::-1]))
|
||||
else:
|
||||
assert False # Sanity check
|
||||
|
||||
return locks, keys
|
||||
|
||||
def fits(lock: Schematic, key: Schematic) -> bool:
|
||||
return all(l + k < 6 for l, k in zip(lock, key))
|
||||
|
||||
locks, keys = parse(input)
|
||||
return sum(fits(lock, key) for lock, key in itertools.product(locks, keys))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = sys.stdin.read()
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
3999
2024/d25/ex1/input
3999
2024/d25/ex1/input
File diff suppressed because it is too large
Load diff
|
|
@ -1,9 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
def main() -> None:
|
||||
print("There is no part two...")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
3999
2024/d25/ex2/input
3999
2024/d25/ex2/input
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue