25 lines
688 B
Python
25 lines
688 B
Python
|
def getDigitsOfLine(line) -> int:
|
||
|
digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
|
||
|
first_digit = 0
|
||
|
last_digit: int = None
|
||
|
for i in range(len(line)):
|
||
|
if line[i] in digits:
|
||
|
if first_digit == 0:
|
||
|
first_digit = digits.index(line[i])
|
||
|
else:
|
||
|
last_digit = digits.index(line[i])
|
||
|
if last_digit == None:
|
||
|
last_digit = first_digit
|
||
|
number = (first_digit * 10) + last_digit
|
||
|
print(f'Number found: {number}')
|
||
|
return number
|
||
|
|
||
|
lines = open('values', 'r').readlines()
|
||
|
|
||
|
number_sum = 0
|
||
|
|
||
|
for line in lines:
|
||
|
if line != '':
|
||
|
number_sum += getDigitsOfLine(line)
|
||
|
|
||
|
print(f'Sum: {number_sum}')
|