-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuzzle03.py
76 lines (66 loc) · 1.69 KB
/
puzzle03.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
with open("input") as f:
inst = f.read()
print(inst)
cur = None
temp = None
fac1 = 0
fac2 = 0
ans = 0
xcur = None
enabled = True
for c in inst:
if xcur is None and c == 'd':
xcur = 'd'
elif xcur == 'd' and c == 'o':
xcur = 'do'
elif xcur == 'do' and c == '(':
xcur = 'do('
elif xcur == 'do(' and c == ')':
enabled = True
xcur = None
elif xcur == 'do' and c == 'n':
xcur = 'don'
elif xcur == 'don' and c == '\'':
xcur = 'don\''
elif xcur == 'don\'' and c == 't':
xcur = 'don\'t'
elif xcur == 'don\'t' and c == '(':
xcur = 'don\'t('
elif xcur == 'don\'t(' and c == ')':
enabled = False
xcur = None
else:
xcur = None
if cur is None and c == 'm':
cur = 'm'
elif cur == 'm' and c == 'u':
cur = 'mu'
elif cur == 'mu' and c == 'l':
cur = 'mul'
elif cur == 'mul' and c == '(':
cur = 'mul('
elif cur == 'mul(' and temp is None and c.isdigit():
temp = c
elif cur == 'mul(' and temp is not None and c.isdigit():
temp += c
elif cur == 'mul(' and temp is not None and c == ',':
cur = 'mul(,'
fac1 = int(temp)
temp = None
elif cur == 'mul(,' and temp is None and c.isdigit():
temp = c
elif cur == 'mul(,' and temp is not None and c.isdigit():
temp += c
elif cur == 'mul(,' and temp is not None and c == ')':
cur = None
fac2 = int(temp)
temp = None
if enabled:
ans += fac1 * fac2
print(fac1, '*', fac2)
else:
print('disabled!')
else:
cur = None
temp = None
print(ans)