jour 1
This commit is contained in:
parent
86f948edb1
commit
58ed6db9d4
|
@ -0,0 +1 @@
|
|||
two1nine
|
|
@ -0,0 +1,4 @@
|
|||
1abc2
|
||||
pqr3stu8vwx
|
||||
a1b2c3d4e5f
|
||||
treb7uchet
|
|
@ -0,0 +1,7 @@
|
|||
two1nine
|
||||
eightwothree
|
||||
abcone2threexyz
|
||||
xtwone3four
|
||||
4nineeightseven2
|
||||
zoneight234
|
||||
7pqrstsixteen
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,11 @@
|
|||
filename = "input.txt"
|
||||
s = 0
|
||||
with open(filename, 'r') as f:
|
||||
for line in f.readlines():
|
||||
mot=[]
|
||||
for car in line:
|
||||
if car.isdigit():
|
||||
mot.append(car)
|
||||
s+=int( "".join([mot[0], mot[-1]]) )
|
||||
|
||||
print(s)
|
|
@ -0,0 +1,25 @@
|
|||
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)
|
Loading…
Reference in New Issue