-
Notifications
You must be signed in to change notification settings - Fork 1
/
gcd.adv
144 lines (126 loc) · 3.09 KB
/
gcd.adv
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
135
136
137
138
139
140
141
think "Greatest common divisor"
e
take shovel
dig with shovel
dig with shovel
e
ne
n
take pen from backpack
take backpack
n
n
n
n
n
n
w
open cupboard
take pan
put dirt into pan
drop pan
put dirt into backpack
e
s
w
open cabinet
take parchment from folder from cabinet
take folder from cabinet
e
s
put parchment into shredder
take first parchment from shredder
call last in me "TESTB"
erase TESTB
write with pen on TESTB "think TESTB"
write with pen on TESTB "take all from scale"
write with pen on TESTB "put A onto scale"
write with pen on TESTB "put B onto scale"
write with pen on TESTB "call first in scale A"
write with pen on TESTB "call last in scale B"
write with pen on TESTB "take A"
write with pen on TESTB "put backpack onto scale"
write with pen on TESTB "take parchment from A"
write with pen on TESTB "take parchment from B"
write with pen on TESTB "take parchment from backpack"
write with pen on TESTB "put DIVIDE into B"
write with pen on TESTB "obey parchment in first in scale"
take first parchment from shredder
call last in me "DIVIDE"
erase DIVIDE
write with pen on DIVIDE "think DIVIDE"
write with pen on DIVIDE "take dirt from folder"
write with pen on DIVIDE "put dirt into B"
write with pen on DIVIDE "take all from scale"
write with pen on DIVIDE "take parchment from A"
write with pen on DIVIDE "take parchment from B"
write with pen on DIVIDE "take parchment from backpack"
write with pen on DIVIDE "put SUBTRACT into A"
write with pen on DIVIDE "put TESTB into B"
write with pen on DIVIDE "put A onto scale"
write with pen on DIVIDE "put B onto scale"
write with pen on DIVIDE "obey parchment in first in scale"
take first parchment from shredder
call last in me "SUBTRACT"
erase SUBTRACT
write with pen on SUBTRACT "think SUBTRACT"
write with pen on SUBTRACT "dig from B with shovel"
write with pen on SUBTRACT "put dirt into folder"
write with pen on SUBTRACT "dig from A with shovel"
write with pen on SUBTRACT "drop dirt in me"
write with pen on SUBTRACT "take all from scale"
write with pen on SUBTRACT "put B onto scale"
write with pen on SUBTRACT "put backpack onto scale"
write with pen on SUBTRACT "take parchment from A"
write with pen on SUBTRACT "take parchment from B"
write with pen on SUBTRACT "take parchment from backpack"
write with pen on SUBTRACT "put SUBTRACT into B"
write with pen on SUBTRACT "put DIVIDE into backpack"
write with pen on SUBTRACT "obey parchment in first in scale"
drop pen
s
s
e
call first in cauldron A
take A from cauldron
call first in cauldron B
take B from cauldron
se
obey TESTB
think "I've got the result in A. Now to print it out."
nw
w
n
n
e
put A into scale
push button
take label
w
n
e
put label into drain
quit
This implements Euler's algorithm to compute greatest common divisor:
given a, b with a > b
repeat:
divide a by b
if remainder == 0:
GCD is b
else
let a = b, b = r
Here's the basic Colossal implementation:
TEST-B:
sort so A >= B
B says DIVIDE
H says DONE
DONE:
dunk the A
DIVIDE:
move dirt from T into B
A says SUBTRACT
B says TEST-B
SUBTRACT:
(dig out of B into T, A into nowhere)
B says SUBTRACT
H says DIVIDE