-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay7.py
37 lines (29 loc) · 843 Bytes
/
Day7.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
import re
with open('Day7.in', 'r') as f:
data = f.readlines()
abba = re.compile(r"(.)(.)\2\1")
amount = 0
for line in data:
all = re.findall(r"\w+", line)
hypernet = re.findall(r"(\[)(\w+)(\])", line);
hypernet = [y for tup in hypernet for y in tup]
valid = False
for word in all:
match = abba.search(word)
if match is not None:
start = match.start()
if word in hypernet:
valid = False
print(word)
print(match)
print("Abba in hypernet");
break
if word[start] == word[start+1]:
continue
print(word)
print(match)
valid = True
if valid:
amount += 1
print("Matched", line)
print(amount)