Files
aoc/2015/5.py
PedroEdiaz 62dade14e1 Add 1 -> 5
2025-10-29 17:19:47 -06:00

31 lines
575 B
Python

#!/usr/bin/env python3
import re
# Fill Input
input = ""
try:
with open("5.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)