-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday25.py
35 lines (29 loc) · 906 Bytes
/
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
#!/usr/bin/env python3
import numpy as np
import regex as re
from collections import defaultdict
from functools import lru_cache as cache
f = open("ressources/day25.txt", "r") #Open File
lines = f.readlines() #Separate in lines
area = []
keys = list()
locks = list()
separations = [-1]+[i for i, line in enumerate(lines) if line == "\n"]
for sep in separations:
start = sep+1
end = sep+8
area = np.array([list(line.replace("\n", "").replace("#", "1").replace(".", "0")) for line in lines[start:end]])
area = area.astype(int)
isKey = np.sum(area[0]) == 0
value = np.sum(area, axis=0)-1
if isKey:
keys.append(value)
else:
locks.append(value)
pairs = 0
for key in keys:
for lock in locks:
total = key+lock
if np.all(total < 6):
pairs += 1
print("Total of unique key/locks pairs is {}".format(pairs))