-
Notifications
You must be signed in to change notification settings - Fork 0
/
day25.py
58 lines (48 loc) · 1.44 KB
/
day25.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Advent of Code 2024 - day 25
from common import get_input
# Part 1
def main1():
input_data = get_input("input25.txt")
keys, locks, max_column_size = parse_data(input_data)
fitting_pairs = 0
for key in keys:
for lock in locks:
if not overlapping(key, lock, max_column_size):
fitting_pairs += 1
print(f"Answer 1 is: {fitting_pairs}")
def overlapping(key, lock, max_column_size):
for i in range(len(key)):
if key[i] + lock[i] > max_column_size:
return True
return False
def parse_data(input_data):
keys = []
locks = []
blocks = []
block = []
for i, line in enumerate(input_data):
if len(line) == 0:
blocks.append(block)
block = []
else:
block.append(line)
blocks.append(block)
for block in blocks:
columns = [[] for _ in range(len(block[0]))]
is_lock = False
if block[0] == "#" * len(block[0]):
is_lock = True
for line in block[1:-1]:
for i, char in enumerate(line):
columns[i].append(char)
columns_sizes = []
for column in columns:
columns_sizes.append(column.count("#"))
if is_lock:
locks.append(columns_sizes)
else:
keys.append(columns_sizes)
max_column_size = len(columns[0])
return keys, locks, max_column_size
if __name__ == "__main__":
main1()