advent/2016/07-1.py

23 lines
417 B
Python
Raw Normal View History

2017-01-14 00:34:25 +00:00
# Python!
import re
with open('07.txt') as file:
rows = file.read().splitlines()
abba = re.compile(r'(\w)(\w)(?<!\1)\2\1')
hynet_seq = re.compile('\[[^\]]*\]')
count = 0
for row in rows:
valid = False
stripped = hynet_seq.sub('|', row)
hynets = hynet_seq.finditer(row)
if abba.search(stripped): valid = True
for h in hynets:
if abba.search(h.group()): valid = False
if valid: count += 1
print(count)