Files
aoc/2015/05.py
2025-10-29 23:23:02 -06:00

32 lines
555 B
Python

import re
# Fill Input
input = ""
try:
with open("05.txt", 'r', encoding='utf-8') as file:
input += file.read()
except Exception as e:
print(f"An error occurred: {e}")
# regex matching
def match(pattern, string):
return re.search(pattern, string) != None
# Convert Corrdenate to string
res1, res2 = 0, 0
for line in input.split("\n"):
res1 += int(match(r"(.)\1", line) and
match(r"(.*[aeiou]){3,}", line) and
not match(r"ab|cd|pq|xy", line) )
res2 += int(match(r"(..).*\1", line) and
match(r"(.).\1", line) )
print(res1, res2)