Je perd l'historique, mais ne stocke plus les fichiers input.txt entre autre choses
17 lines
560 B
Python
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)
|