Skip to content

Commit 5163312

Browse files
committed
Add the images to the euclidian algorithm page
1 parent 3758037 commit 5163312

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
@@ -63,6 +63,8 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two
6363
[import:25-40, lang="LOLCODE"](code/lolcode/euclid.lol)
6464
{% sample lang="bash" %}
6565
[import:24-38, lang="bash"](code/bash/euclid.bash)
66+
{% sample lang="piet" %}
67+
> ![](code/piet/subtract/euclidian_algorithm_subtract_large.png) ![](code/piet/subtract/euclidian_algorithm_subtract.png)
6668
{% endmethod %}
6769

6870
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:
@@ -132,6 +134,8 @@ Modern implementations, though, often use the modulus operator (%) like so
132134
[import:9-23, lang="LOLCODE"](code/lolcode/euclid.lol)
133135
{% sample lang="bash" %}
134136
[import:10-22, lang="bash"](code/bash/euclid.bash)
137+
{% sample lang="piet" %}
138+
> ![](code/piet/mod/euclidian_algorithm_mod_large.png) ![](code/piet/mod/euclidian_algorithm_mod.png)
135139
{% endmethod %}
136140

137141
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:
@@ -209,6 +213,10 @@ and modulo method:
209213
[import, lang="LOLCODE"](code/lolcode/euclid.lol)
210214
{% sample lang="bash" %}
211215
[import, lang="bash"](code/bash/euclid.bash)
216+
{% sample lang="piet" %}
217+
> ![](code/piet/subtract/euclidian_algorithm_subtract_large.png) ![](code/piet/subtract/euclidian_algorithm_subtract.png)
218+
219+
> ![](code/piet/mod/euclidian_algorithm_mod_large.png) ![](code/piet/mod/euclidian_algorithm_mod.png)
212220
{% endmethod %}
213221

214222
<script>

0 commit comments

Comments
 (0)