advent-of-code/2015/day05/day05.py

27 lines
648 B
Python
Raw Permalink Normal View History

def read_from_file(file_name):
_file = open(file_name, 'r')
_read = _file.read().split('\n')
_file.close()
return _read
import re
words = read_from_file('inputs/day05.input')
def solve1():
total = 0
for word in words:
if re.match(r"(.*[aeiou]){3}.*", word) and re.match(r".*([a-z])\1.*", word) and not re.match(r".*(ab|cd|pq|xy).*", word):
total += 1
return total
def solve2():
total = 0
for word in words:
if re.match(r".*([a-z])([a-z]).*\1\2.*", word) and re.match(r".*([a-z]).\1.*", word):
total += 1
return total
print("Pt1:",solve1())
print("Pt2:",solve2())