Advent of Code 2024, Day 25

For the read-in, I used a trick from previous days: instead of keeping state in separate variables and changing it when encountering an empty line or the end of the file, I make the state depend on the modulus of the line number.

Part 1 (0.07 seconds)

import sys

W, H = 5, 5

locks = []
keys = []
with open(sys.argv[1]) as f:
    for i, line in enumerate(f):
        line = line.strip()
        if i % (H+3) == 0:
            pattern = W * [0]
        elif 1 <= i % (H+3) <= H:
            for j, c in enumerate(line):
                pattern[j] += c == "#"
        elif i % (H+3) == (H+1):
            (locks, keys)[line[0] == "#"].append(pattern)

def check(lock, key):
    return all(lock[i]+key[i] <= H for i in range(W))

print(sum(check(lock, key) for lock in locks for key in keys))

2024-12-25

Proxy Information
Original URL
gemini://dkalak.de/aoc/25.gmi
Status Code
Success (20)
Meta
text/gemini; lang=en
Capsule Response Time
173.339471 milliseconds
Gemini-to-HTML Time
0.179252 milliseconds

This content has been proxied by September (ba2dc).