Solve 2024:25 pt 1 "Code Chronicle"
Merry XMAS!
This commit is contained in:
parent
2c2379788d
commit
1b7b30e296
1 changed files with 32 additions and 0 deletions
32
2024-python/output/day_25.py
Normal file
32
2024-python/output/day_25.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
from collections import Counter
|
||||
|
||||
|
||||
def solve(data):
|
||||
grids = [
|
||||
(m.strip()[0], list(map(Counter, zip(*m.split())))) for m in data.split("\n\n")
|
||||
]
|
||||
locks = []
|
||||
keys = []
|
||||
for kind, grid in grids:
|
||||
match kind:
|
||||
case "#":
|
||||
locks.append(tuple(str(g[kind] - 1) for g in grid))
|
||||
case ".":
|
||||
keys.append(tuple(str(7 - g[kind] - 1) for g in grid))
|
||||
p1 = sum(
|
||||
all(int(lock[i]) + int(k[i]) <= 5 for i in range(5))
|
||||
for lock in locks
|
||||
for k in keys
|
||||
)
|
||||
p2 = "God jul!"
|
||||
return p1, p2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open("./input/25.txt", "r") as f:
|
||||
inp = f.read().strip()
|
||||
|
||||
p1, p2 = solve(inp)
|
||||
|
||||
print(p1)
|
||||
print(p2)
|
||||
Loading…
Add table
Reference in a new issue