Created
December 30, 2024 20:42
-
-
Save rodrigogiraoserrao/e21a7190b3aaa2a5964e7d245beeda9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# === 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