aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-12-25 12:16:38 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-12-25 12:16:51 +0100
commit9bffb39837bf92fb5eb4316291070d08886dd4a7 (patch)
treea59234d1cd2e8e40167ead7626c586951f94eda2
parent14175103cc4e90b92a051bd37b2168365b7574db (diff)
Add 2024 day 25 part 1 solutionHEADmaster
-rwxr-xr-x2024/25/puzzle-1.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/2024/25/puzzle-1.py b/2024/25/puzzle-1.py
new file mode 100755
index 0000000..2ad6581
--- /dev/null
+++ b/2024/25/puzzle-1.py
@@ -0,0 +1,30 @@
+#!/usr/bin/python3
+
+import itertools
+
+
+def main() -> None:
+ keys: list[int] = []
+ locks: list[int] = []
+
+ with open("input", "r") as f:
+ schems = f.read().split("\n\n")
+
+ for schem in schems:
+ n = 0
+ for char in schem:
+ if char == '\n':
+ continue
+ n <<= 1
+ if char == '#':
+ n |= 1
+ (locks if n >= 0x7C0000000 else keys).append(n)
+
+ def nand(x: int, y: int) -> bool:
+ return not x & y
+
+ print(sum(itertools.starmap(nand, itertools.product(keys, locks))))
+
+
+if __name__ == "__main__":
+ main() \ No newline at end of file