advent-of-code/2023/1/obfuscated.py

6 lines
232 B
Python
Raw Normal View History

2024-12-25 12:58:02 +01:00
import re
d="zero|one|two|three|four|five|six|seven|eight|nine|\\d)"
def f(l,p):
m=re.search(p,l)[1];return str(d.split("|").index(m)) if m in d else m
print(sum(map(lambda l:int(f(l,f"({d}.*")+f(l,".*("+d)),open(0).readlines())))