aoc2023/d01/run2.py

25 lines
796 B
Python
Raw Normal View History

2023-12-02 07:11:19 +00:00
filename = "input.txt"
s = 0
#letter = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
dictLetter = {"one": "1", "two": "2", "three": "3", "four": "4", "five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9"}
with open(filename, 'r') as f:
for line in f.readlines():
mot=[]
chaine = ""
for car in line:
if car.isdigit():
mot.append(car)
else:
chaine = "".join([chaine, car])
for l in dictLetter.keys():
#print(f"test {l} in {chaine}")
if l in chaine:
mot.append(dictLetter[l])
chaine = chaine[-1]
#print(mot)
s+=int( "".join([mot[0], mot[-1]]) )
print(s)