Skip to content

Commit fe4baba

Browse files
committed
Add the images to the euclidian algorithm page
1 parent 95a1428 commit fe4baba

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

contents/euclidean_algorithm/euclidean_algorithm.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two
5151
[import:8-19, lang="ruby"](code/ruby/euclidean.rb)
5252
{% sample lang="st" %}
5353
[import:1-13, lang="smalltalk"](code/smalltalk/euclid.st)
54+
{% sample lang="piet" %}
55+
> ![](code/piet/subtract/euclidian_algorithm_subtract_large.png) ![](code/piet/subtract/euclidian_algorithm_subtract.png)
5456
{% endmethod %}
5557

5658
Here, we simply line the two numbers up every step and subtract the lower value from the higher one every timestep. Once the two values are equal, we call that value the greatest common divisor. A graph of `a` and `b` as they change every step would look something like this:
@@ -108,6 +110,8 @@ Modern implementations, though, often use the modulus operator (%) like so
108110
[import:1-6, lang="ruby"](code/ruby/euclidean.rb)
109111
{% sample lang="st" %}
110112
[import:15-25, lang="smalltalk"](code/smalltalk/euclid.st)
113+
{% sample lang="piet" %}
114+
> ![](code/piet/mod/euclidian_algorithm_mod_large.png) ![](code/piet/mod/euclidian_algorithm_mod.png)
111115
{% endmethod %}
112116

113117
Here, we set `b` to be the remainder of `a%b` and `a` to be whatever `b` was last timestep. Because of how the modulus operator works, this will provide the same information as the subtraction-based implementation, but when we show `a` and `b` as they change with time, we can see that it might take many fewer steps:
@@ -173,6 +177,10 @@ and modulo method:
173177
[import, lang="ruby"](code/ruby/euclidean.rb)
174178
{% sample lang="st" %}
175179
[import, lang="smalltalk"](code/smalltalk/euclid.st)
180+
{% sample lang="piet" %}
181+
> ![](code/piet/subtract/euclidian_algorithm_subtract_large.png) ![](code/piet/subtract/euclidian_algorithm_subtract.png)
182+
183+
> ![](code/piet/mod/euclidian_algorithm_mod_large.png) ![](code/piet/mod/euclidian_algorithm_mod.png)
176184
{% endmethod %}
177185

178186

0 commit comments

Comments
 (0)