diff options
author | Marvin Borner | 2024-12-25 11:56:25 +0100 |
---|---|---|
committer | Marvin Borner | 2024-12-25 11:57:16 +0100 |
commit | 1333ac4b9279542eb15ac47e3f9e31546383c5b8 (patch) | |
tree | 1fa4a2e9828c874fbda02a066cd5c2741fe9d1ab | |
parent | f149624d1a8188add51705a16bc260794ae19dbd (diff) |
-rwxr-xr-x | 2024/25/solve.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/2024/25/solve.py b/2024/25/solve.py new file mode 100755 index 0000000..516f5ab --- /dev/null +++ b/2024/25/solve.py @@ -0,0 +1,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)) |