Skip to content

Commit 0feed85

Browse files
committed
Add the images to the euclidian algorithm page
1 parent c57c78a commit 0feed85

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
@@ -55,6 +55,8 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two
5555
[import:1-13, lang="smalltalk"](code/smalltalk/euclid.st)
5656
{% sample lang="lolcode" %}
5757
[import:25-40, lang="LOLCODE"](code/lolcode/euclid.lol)
58+
{% sample lang="piet" %}
59+
> ![](code/piet/subtract/euclidian_algorithm_subtract_large.png) ![](code/piet/subtract/euclidian_algorithm_subtract.png)
5860
{% endmethod %}
5961

6062
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:
@@ -116,6 +118,8 @@ Modern implementations, though, often use the modulus operator (%) like so
116118
[import:15-25, lang="smalltalk"](code/smalltalk/euclid.st)
117119
{% sample lang="lolcode" %}
118120
[import:9-23, lang="LOLCODE"](code/lolcode/euclid.lol)
121+
{% sample lang="piet" %}
122+
> ![](code/piet/mod/euclidian_algorithm_mod_large.png) ![](code/piet/mod/euclidian_algorithm_mod.png)
119123
{% endmethod %}
120124

121125
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:
@@ -185,6 +189,10 @@ and modulo method:
185189
[import, lang="smalltalk"](code/smalltalk/euclid.st)
186190
{% sample lang="lolcode" %}
187191
[import, lang="LOLCODE"](code/lolcode/euclid.lol)
192+
{% sample lang="piet" %}
193+
> ![](code/piet/subtract/euclidian_algorithm_subtract_large.png) ![](code/piet/subtract/euclidian_algorithm_subtract.png)
194+
195+
> ![](code/piet/mod/euclidian_algorithm_mod_large.png) ![](code/piet/mod/euclidian_algorithm_mod.png)
188196
{% endmethod %}
189197

190198
<script>

0 commit comments

Comments
 (0)