Skip to content

Commit bd3c95b

Browse files
committed
Add absolute value commands to text code
1 parent 86ee306 commit bd3c95b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,36 @@ function gcd(a, b)
77
return a;
88

99
in(number) A
10+
// absolute of A
11+
duplicate AA
12+
push 1 1AA
13+
duplicate 11AA
14+
subtract 0AA
15+
greater 0/1A // 1 if A > 0, 0 if A <= 0
16+
not 1/0A // 0 if A > 0, 1 if A <= 0
17+
push 1 1 1/0 A
18+
push 3 31 1/0 A
19+
subtract -2 1/0 A
20+
multiply -2/0 A
21+
push 1 1 -2/0 A
22+
add -1/1 A
23+
multiply A
24+
1025
in(number) BA
26+
// absolute of B
27+
duplicate BBA
28+
push 1 1BBA
29+
duplicate 11BBA
30+
subtract 0BBA
31+
greater 0/1BA // 1 if B > 0, 0 if B <= 0
32+
not 1/0BA // 0 if B > 0, 1 if B <= 0
33+
push 1 1 1/0 BA
34+
push 3 31 1/0 BA
35+
subtract -2 1/0 BA
36+
multiply -2/0 BA
37+
push 1 1 -2/0 BA
38+
add -1/1 BA
39+
multiply BA
1140

1241
// Start of loop
1342
duplicate BBA

0 commit comments

Comments
 (0)