This commit is contained in:
2023-12-02 12:18:07 +01:00
parent ea99b85b35
commit b0015c71e9
8 changed files with 600 additions and 11 deletions

18
01/01-1.py Normal file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
input_file = open("input-org", "r")
summe = 0
for line in input_file:
v1, v2 = "", ""
line = line.strip()
for b in line:
if b.isdigit() and v1 == "":
v1 = b
if b.isdigit() and v1 != "":
v2 = b
summe += int(v1+v2)
input_file.close()
print(summe)

View File

@@ -2,16 +2,10 @@
# -*- coding: utf-8 -*-
def numword2int(text):
text = text.replace("one", "o1e")
text = text.replace("two", "t2o")
text = text.replace("three", "t3e")
text = text.replace("four", "f4r")
text = text.replace("five", "f5e")
text = text.replace("six", "s6x")
text = text.replace("seven", "s7n")
text = text.replace("eight", "e8t")
# beim replace Ersetzung mit zahl, anfangs und endbuchstabe, da wörter teilweise überlappen
text = text.replace("one", "o1e").replace("two", "t2o").replace("three", "t3e").replace("four", "f4r")
text = text.replace("five", "f5e").replace("six", "s6x").replace("seven", "s7n").replace("eight", "e8t")
text = text.replace("nine", "n9e")
# text = text.replace("zero", "0")
return text
@@ -26,7 +20,6 @@ for line in input_file:
v1 = b
if b.isdigit() and v1 != "":
v2 = b
print(v1+v2, line)
summe += int(v1+v2)
input_file.close()