Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Commit 730ec27

Browse files
authored
Solve part 1
1 parent 6c4167b commit 730ec27

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Day-25/python/paul2708/day25.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from shared.paul2708.input_reader import *
2+
from shared.paul2708.output import write
3+
4+
lines = read_plain_input(day=25)
5+
keys = []
6+
locks = []
7+
8+
for i in range(0, len(lines), 8):
9+
if lines[i] == "#####":
10+
locks.append(lines[i:i + 7])
11+
else:
12+
keys.append(lines[i:i + 7])
13+
14+
15+
def count_pins(schematic):
16+
is_lock = schematic[0] == "#####"
17+
count_char = "#" if is_lock else "."
18+
19+
heights = []
20+
for i in range(len(schematic[0])):
21+
height = 0
22+
23+
while height + 1 < len(schematic) and schematic[height + 1][i] == count_char:
24+
height += 1
25+
26+
if not is_lock:
27+
height = 5 - height
28+
29+
heights.append(height)
30+
31+
return heights
32+
33+
34+
pairs = 0
35+
for lock in locks:
36+
for key in keys:
37+
if all([a + b < 6 for a, b in zip(count_pins(lock), count_pins(key))]):
38+
pairs += 1
39+
40+
write(f"There are <{pairs}> fitting lock/key pairs.")

0 commit comments

Comments
 (0)