Skip to content

Instantly share code, notes, and snippets.

@rodrigogiraoserrao
Created December 30, 2024 20:42
Show Gist options
  • Save rodrigogiraoserrao/e21a7190b3aaa2a5964e7d245beeda9b to your computer and use it in GitHub Desktop.
Save rodrigogiraoserrao/e21a7190b3aaa2a5964e7d245beeda9b to your computer and use it in GitHub Desktop.
# === Parsing ===
keys = []
locks = []
with open("input.txt", "r") as f:
contents = f.read()
for block in contents.split("\n\n"):
lines = block.splitlines()
counts = [col.count("#") - 1 for col in zip(*lines)]
if lines[0].count("#") == 0:
keys.append(counts)
else:
locks.append(counts)
# === Part 1 ===
from itertools import product
valid_pairings = 0
for key, lock in product(keys, locks):
valid_pairings += all(k + l < 6 for k, l in zip(key, lock))
print(valid_pairings) # 3155
# === Part 2 ===
# SPOILERS AHEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment