aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2024-12-25 11:56:25 +0100
committerMarvin Borner2024-12-25 11:57:16 +0100
commit1333ac4b9279542eb15ac47e3f9e31546383c5b8 (patch)
tree1fa4a2e9828c874fbda02a066cd5c2741fe9d1ab
parentf149624d1a8188add51705a16bc260794ae19dbd (diff)
whr prt2HEADmain
-rwxr-xr-x2024/25/solve.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/2024/25/solve.py b/2024/25/solve.py
new file mode 100755
index 0000000..516f5ab
--- /dev/null
+++ b/2024/25/solve.py
@@ -0,0 +1,35 @@
+#!/bin/env python3
+
+D = [d.split("\n") for d in open("input").read().strip().split("\n\n")]
+
+
+def isKey(d):
+ return "." in d[0] and "#" in d[-1]
+
+
+def isLock(d):
+ return "#" in d[0] and "." in d[-1]
+
+
+def trans(d):
+ return ["".join(d[j][i] for j in range(len(d))) for i in range(len(d[0]))]
+
+
+def linearize(d):
+ return list(map(lambda c: c.strip(".").count("#") - 1, trans(d)))
+
+
+keys = []
+locks = []
+for d in D:
+ if isKey(d):
+ keys.append(linearize(d))
+ elif isLock(d):
+ locks.append(linearize(d))
+
+
+def fits(key, lock):
+ return not any(k + l >= 6 for k, l in zip(key, lock))
+
+
+print(sum(fits(key, lock) for lock in locks for key in keys))