-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday1-p2.py
60 lines (49 loc) · 1.19 KB
/
day1-p2.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import re
f = open("input.txt", "r")
s = f.readlines()
def returnNum(s):
if s == 'one':
return '1'
elif s == 'two':
return '2'
elif s == 'three':
return '3'
elif s == 'four':
return '4'
elif s == 'five':
return '5'
elif s == 'six':
return '6'
elif s == 'seven':
return '7'
elif s == 'eight':
return '8'
elif s == 'nine':
return '9'
elif s == 'zero':
return '0'
digit = ['1','2','3','4','5','6','7','8','9','0']
num = ['zero','one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
condi = digit + num
r = 0
for l in s:
temp = ''
indexes = []
numFound = []
for i in condi:
for index in re.finditer(i, l):
indexes.append(index.start())
numFound.append(i)
first = numFound[indexes.index(min(indexes))]
last = numFound[indexes.index(max(indexes))]
if first in num:
temp += returnNum(first)
elif first in digit:
temp += first
if last in num:
temp += returnNum(last)
elif last in digit:
temp += last
print(temp)
r+=int(temp)
print (r)