aoc2023/solve.py

27 lines
467 B
Python
Raw Normal View History

2023-12-01 10:23:08 -05:00
#!/usr/bin/env python3
2023-12-01 09:29:09 -05:00
import sys
2023-12-01 10:23:08 -05:00
import regex as re
num_values = dict(
one=1,
two=2,
three=3,
four=4,
five=5,
six=6,
seven=7,
eight=8,
nine=9,
)
2023-12-01 09:29:09 -05:00
sum = 0
for line in sys.stdin:
2023-12-01 10:23:08 -05:00
nums = re.findall(r"one|two|three|four|five|six|seven|eight|nine|[1-9]", line, overlapped=True)
nums = [str(num_values.get(x, x)) for x in nums]
first = nums[0]
last = nums[-1]
2023-12-01 09:29:09 -05:00
value = int(first + last)
sum += value
print(sum)