aboutsummaryrefslogtreecommitdiff
path: root/2024/25/solve.py
blob: 516f5abea5eb16148d336aafc792c12752627293 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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))