24 lines
542 B
Python
24 lines
542 B
Python
|
with open("input.txt") as file:
|
||
|
lines = [line.rstrip() for line in file]
|
||
|
|
||
|
first_digit = None
|
||
|
last_digit = None
|
||
|
things = []
|
||
|
|
||
|
for line in lines:
|
||
|
first_digit = None
|
||
|
last_digit = None
|
||
|
for letter in line:
|
||
|
if letter.isdigit():
|
||
|
if first_digit is None:
|
||
|
first_digit = letter
|
||
|
last_digit = letter
|
||
|
else:
|
||
|
last_digit = letter
|
||
|
things.append(int(f"{first_digit}{last_digit}"))
|
||
|
|
||
|
sum = 0
|
||
|
for thing in things:
|
||
|
sum += thing
|
||
|
|
||
|
print(sum)
|