2023/day1/part1.py
Fedaya fbf1c66a39 Nouveau Repository
Je perd l'historique, mais ne stocke plus les fichiers input.txt
entre autre choses
2023-12-02 12:45:07 +01:00

17 lines
560 B
Python

import re
accumulator = 0
with open("input.txt") as input:
while line := input.readline():
if match := re.match(".*?([0-9]).*([0-9]).*?", line):
# print(match.groups(1))
number = int(match.groups(1)[0] + match.groups(1)[1])
# print(number)
accumulator += number
elif match := re.match(".*([0-9]).*", line):
# print(match.groups(1))
number = int(match.groups(1)[0] + match.groups(1)[0])
# print(number)
accumulator += number
print(accumulator)