-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.py
37 lines (30 loc) · 831 Bytes
/
1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from common.cli import get_input
def get_number(entry: str, mappings: dict) -> int:
for i in range(0, len(entry)):
if entry[i].isdigit():
return entry[i]
for match in mappings.keys():
for j in range(0, len(match)):
if entry[i + j] == match[j]:
continue
else:
break
else:
return mappings[match]
numbers = {
"one": "1",
"two": "2",
"three": "3",
"four": "4",
"five": "5",
"six": "6",
"seven": "7",
"eight": "8",
"nine": "9",
}
counter = 0
for entry in get_input():
first = get_number(entry, numbers)
last = get_number(entry[::-1], { key[::-1]: value for key, value in numbers.items() })
counter += int(f"{first}{last}")
print(counter)