-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpseudocode.txt
134 lines (120 loc) · 2.08 KB
/
pseudocode.txt
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
Import input, turn into pseudocode, resolve jump labels, remove unused labels:
b = 57
c = b
a ? goto 4
goto 8
4: b *= 100
b -= -100000
c = b
c -= -17000
8: f = 1
d = 2
10: e = 2
11: g = d
g *= e
g -= b
g ? goto 16
f = 0
16: e -= -1
g = e
g -= b
g ? goto 11
d -= -1
g = d
g -= b
g ? goto 10
f ? goto 26
h -= -1
26: g = b
g -= c
g ? goto 30
exit
30: b -= -17
goto 8
--------------------------------------------------------------------------------
Merge compound statements, detect part2 complication code, detect increments:
b = c = 57
if part2:
b = b * 100 + 100000
c = b + 17000
loop:
f = 1
d = 2
10: e = 2
11: g = d * e - b
g ? goto 16
f = 0
16: e++
g = e - b
g ? goto 11
d++
g = d - b
g ? goto 10
f ? goto 26
h++
26: g = b - c
g ? goto 30
exit
30: b += 17
--------------------------------------------------------------------------------
Extract and optimize if statements:
b = c = 57
if part2:
b = b * 100 + 100000
c = b + 17000
loop8:
f = 1
d = 2
10: e = 2
11: if d * e == b:
f = 0
e++
if e != b:
goto 11
d++
if d != b:
goto 10
if f == 0:
h++
if b == c:
exit
b += 17
--------------------------------------------------------------------------------
Extract loops:
b = c = 57
if part2:
b = b * 100 + 100000
c = b + 17000
loop8:
f = 1
d = 2
loop10:
e = 2
loop11:
if d * e == b:
f = 0
e++
if e == b:
break
d++
if d == b:
break
if f == 0:
h++
if b == c:
exit
b += 17
--------------------------------------------------------------------------------
Detect counting loops:
b = c = 57
if part2:
b = b * 100 + 100000
c = b + 17000
for b1 in b .. c step 17:
flag = False
for d in 2 .. b1:
for e in 2 .. b1:
if d * e == b1:
flag = True
if flag:
h++