Solve 2024 day 25

This commit is contained in:
2024-12-25 10:42:33 -05:00
parent 3dd208c088
commit 8cc199105c
2 changed files with 88 additions and 137 deletions

25
2024/d25.py Normal file
View File

@@ -0,0 +1,25 @@
from lib import get_data
from lib import Grid2D
data = get_data(__file__)
locks = []
keys = []
for o in data.split("\n\n"):
g = Grid2D(o)
if all(g[(0, c)] == "#" for c in range(g.n_cols)):
keys.append(g)
elif all(g[g.n_rows - 1, c] == "#" for c in range(g.n_cols)):
locks.append(g)
else:
assert False
t = 0
for key in keys:
for lock in locks:
k = key.find("#")
l = lock.find("#")
if len(k) + len(l) == len(set(k) | set(l)):
t += 1
print(t)