This commit is contained in:
Arthur 2023-12-02 08:11:19 +01:00
parent 86f948edb1
commit 58ed6db9d4
6 changed files with 1048 additions and 0 deletions

1
d01/exemple.txt Normal file
View File

@ -0,0 +1 @@
two1nine

4
d01/exemple1.txt Normal file
View File

@ -0,0 +1,4 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet

7
d01/exemple2.txt Normal file
View File

@ -0,0 +1,7 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen

1000
d01/input.txt Normal file

File diff suppressed because it is too large Load Diff

11
d01/run1.py Normal file
View File

@ -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)

25
d01/run2.py Normal file
View File

@ -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)