parent
01e799b65c
commit
74ff1d77ab
2 changed files with 46 additions and 3 deletions
@ -0,0 +1,32 @@ |
|||||||
|
lines = [i for i in open("input.txt", 'r').read().splitlines()] |
||||||
|
|
||||||
|
sum = 0 |
||||||
|
words = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"] |
||||||
|
|
||||||
|
for l in lines: |
||||||
|
first = "" |
||||||
|
firstFound = False |
||||||
|
last = "" |
||||||
|
lastFound = False |
||||||
|
n = len(l) |
||||||
|
for i in range(n): |
||||||
|
if not firstFound and l[i].isnumeric(): |
||||||
|
first = l[i] |
||||||
|
firstFound = True |
||||||
|
if not lastFound and l[-i-1].isnumeric(): |
||||||
|
last = l[-i-1] |
||||||
|
lastFound = True |
||||||
|
for j in range(len(words)): |
||||||
|
m = len(words[j]) |
||||||
|
if not firstFound and l[i:i+m] == words[j]: |
||||||
|
first = str(j) |
||||||
|
firstFound = True |
||||||
|
if not lastFound and l[-(i+m):n-i] == words[j]: |
||||||
|
last = str(j) |
||||||
|
lastFound = True |
||||||
|
if firstFound and lastFound: |
||||||
|
break |
||||||
|
s = first + last |
||||||
|
sum += int(s) |
||||||
|
|
||||||
|
print(sum) |
Loading…
Reference in new issue