-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path25.py
49 lines (36 loc) · 939 Bytes
/
25.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
locks, keys = [], []
temp = []
def get_group(group):
return locks if set(group[0]) == set("#") else keys
with open("data/25.txt") as file:
for line in file:
line = line.strip()
if line:
temp.append(line)
else:
get_group(temp).append(temp)
temp = []
if temp:
get_group(temp).append(temp)
intlocks = [
[
[lock[row][col] for row in range(len(lock))].index(".") - 1
for col in range(len(lock[0]))
]
for lock in locks
]
intkeys = [
[
[key[row][col] for row in range(len(key) - 1, -1, -1)].index(".") - 1
for col in range(len(key[0]))
]
for key in keys
]
def isoverlap(lock, key, maxheight):
for i in range(len(lock)):
if lock[i] + key[i] >= maxheight:
return False
return True
print(
sum(isoverlap(lock, key, len(locks[0]) - 1) for lock in intlocks for key in intkeys)
)