From 1286703bd7b932f3253b7e1b756b338637141a90 Mon Sep 17 00:00:00 2001 From: Thijs Raymakers Date: Thu, 4 Oct 2018 21:14:39 +0200 Subject: [PATCH 01/13] Add Piet program for Euclidian Algorithm with the modulo operator --- .../code/piet/euclidian_algorithm_mod.png | Bin 0 -> 136 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 contents/euclidean_algorithm/code/piet/euclidian_algorithm_mod.png diff --git a/contents/euclidean_algorithm/code/piet/euclidian_algorithm_mod.png b/contents/euclidean_algorithm/code/piet/euclidian_algorithm_mod.png new file mode 100644 index 0000000000000000000000000000000000000000..62459a1357e2fe1a3e6c758440c000eaac6da61f GIT binary patch literal 136 zcmeAS@N?(olHy`uVBq!ia0vp^+(692!2~3)&j?xqq&N#aB8wRq^pruEv0|xx8Boy5 z)5S4_<9hDdjl72)7!DsO7CZgwR*$BPO-zKWqLWZ`+KI50l_wRJ-sY(3yI>x(&fac` gvEkKS{QiHL*UVAL{#N+sIM5UZPgg&ebxsLQ03Kp0bN~PV literal 0 HcmV?d00001 From f8929ce44732f2ce565ef7671f7bd9e5a9e41c86 Mon Sep 17 00:00:00 2001 From: Thijs Raymakers Date: Thu, 4 Oct 2018 21:36:00 +0200 Subject: [PATCH 02/13] Add larger version of the euclidian algorithm for human readers --- .../code/piet/euclidian_algorithm_mod_large.png | Bin 0 -> 786 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 contents/euclidean_algorithm/code/piet/euclidian_algorithm_mod_large.png diff --git a/contents/euclidean_algorithm/code/piet/euclidian_algorithm_mod_large.png b/contents/euclidean_algorithm/code/piet/euclidian_algorithm_mod_large.png new file mode 100644 index 0000000000000000000000000000000000000000..026568aad1920cdc7e5c12fff6c2313bdada2eca GIT binary patch literal 786 zcmeAS@N?(olHy`uVBq!ia0y~yU{V9JPjD~+$>7?(r+^e^fk$L91B0G22s2hJwJ!sz zI^yZ#7*cWT?e&YihYdJfF9wvZH`rw>8GCU4`B#?03Qk2+XQ^L|>n#2n+!(ypuck@1 zG9p{O@9RF%pJM9{%v_~(er~e7HiJVE!vq-+QekH}$p}P10f-n-07(q42rLFyL_Lij z!C?h^MJ+?s`ApC6nEp8R?GgU4(kHP$clvPH;~Rb}dZSFgscyS%$=&Z<9889tmxjX;&- mT+rA@6{lXr;ttqze;Jx{6oq$bMoR({IfJLGpUXO@geCy=UeQVb literal 0 HcmV?d00001 From 9b4454e5ae0e096212253dd1c3dc0aac5c7dd604 Mon Sep 17 00:00:00 2001 From: Thijs Raymakers Date: Fri, 5 Oct 2018 00:06:57 +0200 Subject: [PATCH 03/13] Add basic euclidian algorithm subtraction in Piet --- .../code/piet/euclidian_algorithm.piet | 97 ++++++++++++++++++ .../{ => mod}/euclidian_algorithm_mod.png | Bin .../code/piet/mod/euclidian_algorithm_mod.ppm | Bin 0 -> 189 bytes .../euclidian_algorithm_mod_large.png | Bin .../subtract/euclidian_algorithm_subtract.png | Bin 0 -> 327 bytes .../subtract/euclidian_algorithm_subtract.ppm | Bin 0 -> 2410 bytes 6 files changed, 97 insertions(+) create mode 100644 contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet rename contents/euclidean_algorithm/code/piet/{ => mod}/euclidian_algorithm_mod.png (100%) create mode 100644 contents/euclidean_algorithm/code/piet/mod/euclidian_algorithm_mod.ppm rename contents/euclidean_algorithm/code/piet/{ => mod}/euclidian_algorithm_mod_large.png (100%) create mode 100644 contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.png create mode 100644 contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.ppm diff --git a/contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet b/contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet new file mode 100644 index 000000000..e400523e8 --- /dev/null +++ b/contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet @@ -0,0 +1,97 @@ +function gcd(a, b) + while a ≠ b + if a > b + a := a − b; + else + b := b − a; + return a; + +in(number) A +in(number) BA + +// Start of loop +duplicate BBA +push 3 3BBA +push 2 23BBA +roll ABB +duplicate AABB +push 4 4AABB +push 1 14AABB +roll ABBA +subtract 0/x BA +not 1/0 BA // 1 if a = b and 0 if a ≠ b +not 0/1 BA // 1 if a ≠ b and 0 if a = b +pointer BA + + // Go down if a ≠ b + duplicate BBA + push 3 3BBA + push 2 23BBA + roll ABB + duplicate AABB + push 4 4AABB + push 1 14AABB + roll ABBA + push 2 2ABBA + push 1 12ABBA + roll BABA + greater 0/1 BA // A > B; 1 if true; 0 if false + pointer BA // maybe a switch here instead? + + // If A > B + duplicate BBA + push 3 3BBA + push 1 13BBA + roll BAB + subtract AB // A = A - B + push 2 2AB + push 1 12AB + roll BA + // Go back to start of loop + + // If B > A + // b = b - a + push 2 2BA + push 1 12BA + roll AB + duplicate AAB + push 3 3AAB + push 1 13AAB + roll ABA + subtract BA // B = B - A + // Go back to start of loop + +// Go right if a = b (end of while loop) +pop A +out(number) - + +--------------------------------------------------------------------------- + +function gcd(a, b) + while b ≠ 0 + t := b; + b := a mod b; + a := t; + return a; + +in(number) A +in(number) BA + +// Start of loop +duplicate BBA +not 0/1 BA +not 1/0 BA +pointer BA + + // Go down if b ≠ 0 + duplicate TBA + push 3 3TBA + push 1 13TBA + roll BAT + mod BA // b = a mod b; a = t + // Go back to the start of the loop + +// Go right if b = 0 +pop A +out(number) - + diff --git a/contents/euclidean_algorithm/code/piet/euclidian_algorithm_mod.png b/contents/euclidean_algorithm/code/piet/mod/euclidian_algorithm_mod.png similarity index 100% rename from contents/euclidean_algorithm/code/piet/euclidian_algorithm_mod.png rename to contents/euclidean_algorithm/code/piet/mod/euclidian_algorithm_mod.png diff --git a/contents/euclidean_algorithm/code/piet/mod/euclidian_algorithm_mod.ppm b/contents/euclidean_algorithm/code/piet/mod/euclidian_algorithm_mod.ppm new file mode 100644 index 0000000000000000000000000000000000000000..2292b07d3ecaea7daeff512c38ef85fd0fa2024e GIT binary patch literal 189 zcmWGA<5E^|E=o--Nlj5ms#I|I^bJrbOD!tS%+FIW(la#BGgAog^HnIwDNWbS%;PdN zR50N(GBxG;&%kitz<-7VK*+!Vq!0Z6|DWOie-IBH8~_P`B!LL50H_xkfOLWZL;+9@ TkdLeeWC=(sQ1bzpN)QbIemy#O literal 0 HcmV?d00001 diff --git a/contents/euclidean_algorithm/code/piet/euclidian_algorithm_mod_large.png b/contents/euclidean_algorithm/code/piet/mod/euclidian_algorithm_mod_large.png similarity index 100% rename from contents/euclidean_algorithm/code/piet/euclidian_algorithm_mod_large.png rename to contents/euclidean_algorithm/code/piet/mod/euclidian_algorithm_mod_large.png diff --git a/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.png b/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.png new file mode 100644 index 0000000000000000000000000000000000000000..684df44549810de5a77f0abb2b3aab5a7553d3fe GIT binary patch literal 327 zcmV-N0l5B&P)WZFn*tqI=)iuLjQ8KTmvd-KJentFUI_nB8xpGFxYfa?|8LnGZ-IfHFURluH> zT0El%_tb04o5zs0qoY-+h@Hb0rAqA@rb%gWZ7tZEevG}-2ZW~o)KjT`Wu7iSs%K5V zXa3>20-b79l-3jGUkz>B5rK`3BM30zr~toE)AN&Q+kgY55g5Xgz$qy8xEggvY0D%n Z+yFR2@FDuKr;z{v002ovPDHLkV1f_YhN%Dm literal 0 HcmV?d00001 diff --git a/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.ppm b/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.ppm new file mode 100644 index 0000000000000000000000000000000000000000..1f2476f59c13ad5db4f23221b3fcd79157fe9680 GIT binary patch literal 2410 zcmeH{O=`n15QVk&DFj_7w1$N2yC_|x_zEpGArR7%{y=XxH&fs9*g=dGY>{MBIuT-K zH2U-y$!V6=jlVy%&!6q9fBEqbkL$*Nw}+4I+uqmnyW9EFH&1K-zWdtDw)?7H`Fd5= zi$xWj3m3P4=4D$N_0tV@?g?NzClZ|C*N=dhDOi++8wAxT3vgJV0TGaa>Z};WoLWt{ zbbPX5f*^<0WOgY9A|oAyOh~47Y_)1NljgI)BNGm`WP!SLoZ*Zcx;oe?C8aufm19=S zOuCnzP|8FXQ;5kFF`WR(VIU?fVq)(okTqR@bT-FjLws4;e4H$0>Q@;PQoocbSGf0U zF#qJ6$7M}15mu#l9cOF-%LN9n9Yc(-Ow1Dv+fivCCNu?9$iInR S9s^}i`w&fFPE;6|8DYPfUXp77 literal 0 HcmV?d00001 From d4b17ab51836228cefcb73d2b8155e156280e734 Mon Sep 17 00:00:00 2001 From: Thijs Raymakers Date: Fri, 5 Oct 2018 23:10:13 +0200 Subject: [PATCH 04/13] Refactor euclidian algorithm subtract in Piet --- .../subtract/euclidian_algorithm_subtract.ppm | Bin 2410 -> 8189 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.ppm b/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.ppm index 1f2476f59c13ad5db4f23221b3fcd79157fe9680..b8e6cf4316d965e53caa1c60e670d91b16384ede 100644 GIT binary patch literal 8189 zcmeHL%Wm6147}?r7U;c5UF6We$R7l18l(o|#&DefugLXqIgu%^SAOK+gQ9ZD9nK6_ z+olgcyKkva>*ez{tv7Ekn|_s^Kb~Hff0q5f$Nu%@ZL{3|T|K^k{N8T*r|tLkdetrN z)8c;ksZUDjEK}so*T3L`s5G~lD?4Z#j@Ac55J^<+?ld0@$ ziZUar(5TOE*N4#v8r<{^EqPJo;t@zZsuY2(YE!IgV4DRbYX>4=hj%U72-*;RrU}gh z5Yf(hC}GE1oyjUi(~z-%O!R?H!Azm1abWde07^}0)JLEVjWTlso&tJgDc(ftLrQ1+ z7D6*OYD#6J859Da{-s z6VJ&lb|=nwap&ab`%IWv?!(>hC18FrZfK})VjX5K#*OI2fj99wH+g8)#BCYtsmq*U z3S#6DcVc|5o4AE0UT3DQQz$Z`JMqN65z*59^Z(WO3?0kLfTwT)v?ESp(|IG`e85V5 zCZ60lBM!-4JslWiy7E0#?gpRrYCi6krbz7=4JF1Y-#(t<11* zN)Vp_khBkF!e9a|+`~$JSuNUL6GyCVrkWvf4FRKh)~u%vn$bj$odacyk&sepYGo3j zl+RntEzWq>JO!VrJYrPFN(n8d6K0rOSjHm>%f@JM)Btore%Or41a_AL;8iIC1JDJM zT^CIFRtHc!g&3`9`TXzRFvGIz%EnVD`|useJ0|KgU%)p{hgjdZwfzNl^X=xFd{p!? QQE)pUQ|^#e6tHjIe+KGsg8%>k literal 2410 zcmeH{O=`n15QVk&DFj_7w1$N2yC_|x_zEpGArR7%{y=XxH&fs9*g=dGY>{MBIuT-K zH2U-y$!V6=jlVy%&!6q9fBEqbkL$*Nw}+4I+uqmnyW9EFH&1K-zWdtDw)?7H`Fd5= zi$xWj3m3P4=4D$N_0tV@?g?NzClZ|C*N=dhDOi++8wAxT3vgJV0TGaa>Z};WoLWt{ zbbPX5f*^<0WOgY9A|oAyOh~47Y_)1NljgI)BNGm`WP!SLoZ*Zcx;oe?C8aufm19=S zOuCnzP|8FXQ;5kFF`WR(VIU?fVq)(okTqR@bT-FjLws4;e4H$0>Q@;PQoocbSGf0U zF#qJ6$7M}15mu#l9cOF-%LN9n9Yc(-Ow1Dv+fivCCNu?9$iInR S9s^}i`w&fFPE;6|8DYPfUXp77 From 4d2cc2bb0ae972f31d979deb8b8893d9b3c886f5 Mon Sep 17 00:00:00 2001 From: Thijs Raymakers Date: Sat, 6 Oct 2018 00:13:27 +0200 Subject: [PATCH 05/13] Add absolute value commands to text code --- .../code/piet/euclidian_algorithm.piet | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet b/contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet index e400523e8..96d437b8e 100644 --- a/contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet +++ b/contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet @@ -7,7 +7,36 @@ function gcd(a, b) return a; in(number) A +// absolute of A +duplicate AA +push 1 1AA +duplicate 11AA +subtract 0AA +greater 0/1A // 1 if A > 0, 0 if A <= 0 +not 1/0A // 0 if A > 0, 1 if A <= 0 +push 1 1 1/0 A +push 3 31 1/0 A +subtract -2 1/0 A +multiply -2/0 A +push 1 1 -2/0 A +add -1/1 A +multiply A + in(number) BA +// absolute of B +duplicate BBA +push 1 1BBA +duplicate 11BBA +subtract 0BBA +greater 0/1BA // 1 if B > 0, 0 if B <= 0 +not 1/0BA // 0 if B > 0, 1 if B <= 0 +push 1 1 1/0 BA +push 3 31 1/0 BA +subtract -2 1/0 BA +multiply -2/0 BA +push 1 1 -2/0 BA +add -1/1 BA +multiply BA // Start of loop duplicate BBA From 2ced02770ec21a6dceee6d897be0c474fe9672eb Mon Sep 17 00:00:00 2001 From: Thijs Raymakers Date: Sat, 6 Oct 2018 00:39:50 +0200 Subject: [PATCH 06/13] Add working Piet program with absolute operator in it --- .../code/piet/euclidian_algorithm.piet | 4 +- .../subtract/euclidian_algorithm_subtract.ppm | 169 ++++++++++++------ 2 files changed, 112 insertions(+), 61 deletions(-) diff --git a/contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet b/contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet index 96d437b8e..57122f5bd 100644 --- a/contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet +++ b/contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet @@ -52,7 +52,7 @@ not 1/0 BA // 1 if a = b and 0 if a ≠ b not 0/1 BA // 1 if a ≠ b and 0 if a = b pointer BA - // Go down if a ≠ b + // Go left if a ≠ b duplicate BBA push 3 3BBA push 2 23BBA @@ -90,7 +90,7 @@ pointer BA subtract BA // B = B - A // Go back to start of loop -// Go right if a = b (end of while loop) +// Go down if a = b (end of while loop) pop A out(number) - diff --git a/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.ppm b/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.ppm index b8e6cf431..0a4614c4d 100644 --- a/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.ppm +++ b/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.ppm @@ -1,95 +1,146 @@ P3 # a piet program euclidian_algorithm_subtract.ppm -25 25 +31 30 255 -255 0 0 192 192 255 0 192 0 192 0 0 192 0 0 255 192 192 -255 192 192 255 0 0 0 0 192 0 192 0 0 192 0 192 255 192 - 0 255 0 192 0 0 255 255 192 0 192 192 255 0 255 0 192 0 - 0 255 0 0 255 0 0 0 0 192 192 0 0 0 0 255 255 255 -255 255 255 255 255 255 255 255 255 0 0 0 192 0 0 0 0 0 -255 255 255 255 255 255 255 255 255 255 255 255 0 192 0 255 255 255 -255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 192 0 0 -192 0 0 0 0 0 0 255 0 0 255 0 192 192 0 192 192 0 - 0 0 0 255 255 255 255 255 255 255 255 255 0 0 0 0 192 0 - 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 0 192 0 -255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 192 0 0 0 0 0 255 255 255 0 0 0 192 192 0 - 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 -255 255 255 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 192 192 0 192 0 192 192 192 255 255 255 255 192 0 255 0 +255 0 255 255 255 192 255 255 0 255 255 0 192 192 0 192 255 192 + 0 192 192 192 255 255 192 192 255 192 0 192 0 255 255 255 255 0 +192 192 0 192 0 192 255 192 192 192 255 255 192 0 192 255 192 255 +255 192 255 255 0 255 192 0 0 255 255 0 192 192 0 0 192 0 + 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 0 255 255 255 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +255 192 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 255 255 255 255 192 192 0 0 0 255 255 255 255 255 255 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 - 0 0 0 255 255 255 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 255 255 255 255 255 255 255 192 192 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 0 0 0 255 255 255 0 0 0 255 255 255 255 255 255 + 0 255 255 255 255 0 255 255 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 0 0 +255 255 255 0 0 0 255 255 255 0 0 0 255 255 255 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 255 255 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 255 255 255 0 0 0 255 255 255 -255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0 0 192 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 192 192 0 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 255 255 255 0 0 0 +255 255 255 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 255 255 255 255 255 255 255 255 255 0 192 0 0 192 0 - 0 192 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 255 255 255 - 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 192 192 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 0 192 0 0 0 0 255 255 255 255 255 255 255 255 255 -255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 -255 255 255 0 0 0 0 0 0 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 192 192 0 + 0 0 0 255 192 192 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 255 255 255 192 255 192 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 - 0 0 0 255 255 255 0 0 0 0 0 0 255 255 255 255 255 255 +255 255 192 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 +255 0 0 0 0 0 0 192 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 255 255 255 255 255 255 0 255 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 0 0 0 255 255 255 0 0 0 255 255 255 255 255 255 +255 255 255 255 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 255 255 255 255 255 255 255 255 255 192 0 0 0 0 0 + 0 0 0 192 255 192 0 0 0 0 255 0 0 0 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 255 255 255 0 0 0 255 255 255 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 192 0 0 + 0 255 255 0 255 255 0 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 0 0 0 0 192 0 0 0 0 192 255 192 0 0 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 255 255 255 255 255 255 0 0 0 255 255 255 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 192 192 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 255 255 255 +255 255 255 255 255 255 0 0 0 0 255 0 0 0 0 192 255 192 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 255 0 0 0 0 0 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 0 192 192 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 0 0 0 0 255 0 0 255 0 +192 192 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 192 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 0 0 255 + 0 0 0 0 255 255 0 0 0 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 -255 255 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 192 0 0 0 255 255 255 255 255 255 +255 192 192 0 0 0 192 255 255 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 - 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 0 255 -255 255 192 192 192 0 255 255 0 255 255 0 255 192 192 0 192 0 - 0 255 0 192 255 192 192 255 192 192 192 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 - 0 0 0 0 0 0 255 255 255 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 192 255 192 192 192 255 0 0 0 +255 255 255 0 192 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 0 0 0 0 0 0 255 255 255 255 255 255 255 255 255 -255 255 255 192 192 0 255 0 0 192 255 192 0 192 0 0 255 0 - 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 255 255 255 - 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 255 255 255 0 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 255 0 0 0 255 255 192 192 192 0 0 255 0 0 -255 0 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 + 0 0 0 192 0 0 0 0 0 0 192 192 0 0 0 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 0 0 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 0 0 0 255 0 0 0 0 0 0 192 192 0 192 192 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 0 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 0 255 192 192 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 0 0 0 255 0 0 255 255 255 192 0 192 + 0 255 0 255 0 255 255 255 192 192 192 0 255 255 0 255 255 0 +192 255 255 0 192 192 0 255 255 0 255 255 255 0 255 255 255 192 +192 192 0 192 192 0 255 255 0 255 255 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 192 255 255 192 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 192 255 255 + 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 0 0 0 0 255 0 + 0 255 0 0 255 0 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 + 0 0 0 0 255 0 0 0 0 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 0 0 0 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 +255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 @@ -106,4 +157,4 @@ P3 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 -255 255 255 + From ca31a494225d8adf88e6ab482824f01c226cbdd7 Mon Sep 17 00:00:00 2001 From: Thijs Raymakers Date: Sat, 6 Oct 2018 00:49:29 +0200 Subject: [PATCH 07/13] Add some comments to piet pseudocode file --- .../code/piet/euclidian_algorithm.piet | 56 +++++++++++++------ 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet b/contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet index 57122f5bd..d91499ae5 100644 --- a/contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet +++ b/contents/euclidean_algorithm/code/piet/euclidian_algorithm.piet @@ -1,3 +1,14 @@ +This file describes the path that the Piet program takes in a more human readable form. +Two functions are implemented: +- GCD with subtraction +- GCD with the modulo operator + +------------------- +SUBTRACTION +------------------- + +Pseudo code: + function gcd(a, b) while a ≠ b if a > b @@ -6,9 +17,12 @@ function gcd(a, b) b := b − a; return a; -in(number) A -// absolute of A -duplicate AA + +Piet code: + +COMMAND STATE OF STACK +in(number) A // Take A as an input +duplicate AA // Start to take the absolute value of A push 1 1AA duplicate 11AA subtract 0AA @@ -20,11 +34,10 @@ subtract -2 1/0 A multiply -2/0 A push 1 1 -2/0 A add -1/1 A -multiply A +multiply A // A should now be an absolute value -in(number) BA -// absolute of B -duplicate BBA +in(number) BA // Take B as an input +duplicate BBA // Start to take the absolute value of B push 1 1BBA duplicate 11BBA subtract 0BBA @@ -36,9 +49,9 @@ subtract -2 1/0 BA multiply -2/0 BA push 1 1 -2/0 BA add -1/1 BA -multiply BA +multiply BA // B should now be an absolute value -// Start of loop +// Start of the main loop while a ≠ b duplicate BBA push 3 3BBA push 2 23BBA @@ -50,9 +63,9 @@ roll ABBA subtract 0/x BA not 1/0 BA // 1 if a = b and 0 if a ≠ b not 0/1 BA // 1 if a ≠ b and 0 if a = b -pointer BA +pointer BA // If a ≠ b, the DP should change one clockwise, otherwise, go straight ahead. - // Go left if a ≠ b + // Go left if a ≠ b (DP changed one clockwise) duplicate BBA push 3 3BBA push 2 23BBA @@ -65,9 +78,9 @@ pointer BA push 1 12ABBA roll BABA greater 0/1 BA // A > B; 1 if true; 0 if false - pointer BA // maybe a switch here instead? + pointer BA // If A > B, DP goes one clockwise, otherwise, DP stays the same. - // If A > B + // If A > B (DP has changed 1 clockwise) duplicate BBA push 3 3BBA push 1 13BBA @@ -78,8 +91,7 @@ pointer BA roll BA // Go back to start of loop - // If B > A - // b = b - a + // If B > A (DP stayed the same) push 2 2BA push 1 12BA roll AB @@ -92,10 +104,16 @@ pointer BA // Go down if a = b (end of while loop) pop A -out(number) - +out(number) - // Print out A when done. --------------------------------------------------------------------------- +------------------- +MODULO +------------------- + +Pseudo code: + function gcd(a, b) while b ≠ 0 t := b; @@ -103,6 +121,9 @@ function gcd(a, b) a := t; return a; +Piet code: + +COMMAND STATE OF STACK in(number) A in(number) BA @@ -122,5 +143,4 @@ pointer BA // Go right if b = 0 pop A -out(number) - - +out(number) - // Print out A when done. From 6f35490f08359c434d2f891f926413e7928947ab Mon Sep 17 00:00:00 2001 From: Thijs Raymakers Date: Sat, 6 Oct 2018 01:23:52 +0200 Subject: [PATCH 08/13] Add some art to fill up the empty space in the euclidian subtraction Piet program --- .../subtract/euclidian_algorithm_subtract.ppm | Bin 12154 -> 2011 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.ppm b/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.ppm index 0a4614c4da6f373f31bf40c5510e356137b5d5a5..3b7c0fbe1e2cf06c2a552c2116887b1a96f89595 100644 GIT binary patch literal 2011 zcmb_cQBDFu44wVmQ%vF)CKAEG1^h66V7P)tVn_@cP!rwD%>nQbT*UfbJ1ha|giY*r z%S@+zZKqwPUlyhHOU?+WG@(U<&b}J!~wY+(^4tt zF7vcIsZUN^n&7d4w-Srf$!eE%iH8@IRCWS4*W$QvxRB-)B^gb(TJSJ>XkwcU^ z_@}>`kgS8p09KQ2{(CJe-+AuVMuNu%uHQQgIQ3eXL$X0{BzUZdDy+s1nHx67#bqR` zLzvU(lDRdjSBb~0j(OuJQM%yA>e6m~RpK%62&&+QZ`%WzuVANz!b~)DC^hKBX=1qIFRnSe{y;<4pQt7xtT!uyjcUHU^D(Ni?Lssy@xO6@uIImLKBK^DM Gm4siA3(7qJ literal 12154 zcmeHN(Nfz$41CX5c&6_iAj3odqJO}oz|hQ)l1an=H!EjlEr*P;osgt{pm!_jq}9sj z1g1advv1X+S}z~B)q3;tv{|gG$JhJk<->CE=Wg-*^s-rQf3NQTzW&;77Wdol>-B0j zzpmz2vzyyn{8ae4{&7>)|5R7|b-!^BLoMFVRJ$+$td`9UjJE^?@OlCRa9apG*f8}B zZuin-wPho|YKy;DyMZU9b}8_U)M_)I${ zKyj~bXUqaCxiyBpwKjYnSf}G<16!X$lNQX!;70LP9a>GQ6nu6HA7qn$(xM%Sj?8T+ z9bx_cU9k39N5BWV@l1P|Fvx-GmXD;HXXLveMTdf}+$gWrBPg_1-O{jJc=5DkleVQ! z>d{W+Ob^h)?O56TlMHXbSoCYSrNYZATDj$CVn5QH0L|9zj3f{+JX;*e@NBW4UfD!m z;U*r`X}t0CG%^sW1oYyTran+MG$^e5fZ^Pt@RqGHMB!mI#%7G3W9x=`eWa2zrEX}j zZ|X7|MUkQ%fqpJPbY!c=kHS0SVkFH7_rDnpp(Csh(5Z7{KQP!U+CAKuCj}#OlR8mR zZSAA*)n2Xm7IU_gU! zj4-VQ=)ld}W2z;8>~m0LM*Cdl=(!U-+QCS`f)>^I(kl^Qw)ogY;puA zz>QR}I!S?esje zrSmz{ckg*lA!R*H;myaCyaJ|M-=>a8C1BER(haX1c_;)-Pe_|OB9(wiw@J6@X4U_7 RcDf7GU6}5|e|HyV{{U^rKt})o From 3758037ec8ea5f16454fba562e54f9f1c5676ba8 Mon Sep 17 00:00:00 2001 From: Thijs Raymakers Date: Sat, 6 Oct 2018 01:31:01 +0200 Subject: [PATCH 09/13] Add larger .png file for subtract method --- .../code/piet/mod/euclidian_algorithm_mod.ppm | Bin 189 -> 0 bytes .../subtract/euclidian_algorithm_subtract.png | Bin 327 -> 500 bytes .../subtract/euclidian_algorithm_subtract.ppm | Bin 2011 -> 0 bytes .../euclidian_algorithm_subtract_large.png | Bin 0 -> 2473 bytes 4 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 contents/euclidean_algorithm/code/piet/mod/euclidian_algorithm_mod.ppm delete mode 100644 contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.ppm create mode 100644 contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract_large.png diff --git a/contents/euclidean_algorithm/code/piet/mod/euclidian_algorithm_mod.ppm b/contents/euclidean_algorithm/code/piet/mod/euclidian_algorithm_mod.ppm deleted file mode 100644 index 2292b07d3ecaea7daeff512c38ef85fd0fa2024e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 189 zcmWGA<5E^|E=o--Nlj5ms#I|I^bJrbOD!tS%+FIW(la#BGgAog^HnIwDNWbS%;PdN zR50N(GBxG;&%kitz<-7VK*+!Vq!0Z6|DWOie-IBH8~_P`B!LL50H_xkfOLWZL;+9@ TkdLeeWC=(sQ1bzpN)QbIemy#O diff --git a/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.png b/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.png index 684df44549810de5a77f0abb2b3aab5a7553d3fe..94070f61a3a9cc91b27fb549762ad7e2dcd12402 100644 GIT binary patch delta 480 zcmV<60U!Ry0`vnjiBL{Q4GJ0x0000DNk~Le0000V0000L2nGNE0KPRfUjP6A24YJ` zL;wH)0002_L%V;GAs~MR7aTLH_;CaP00DtXL_t(Y$Gw&@ZsafwMIVFQW9vzq?X4^9 zc~a*RIYiFz)dwkO>g+-Grx0yb9)LdstB$!i z0^3Byz5{svzHM(5zrBDi;Qn{vbT_P%GV=Gw9qEj__FV%E>h1wv8A+k3HT`PcefQI( zmiB|U!B5d>9{>VMMzM})PVs=wNjo!0cUhDuET{MuxX;rb19Ue>N-ea&MWKAX*Twmo z&Uqj=a1Xt;XPAF}kZ`r;JOBGQ&J+Wgfjy#WO7NG_XVosdc%k0+*-j+*>tN8TMCoMT zRc32)_7K}e=H%$05|lE=?70$N`jLbiq1%ZIzDa$f9?bfRDUlqd^LfWZFn*tqI=)iuLjQ8KTmvd-KJentFUI_nB8xpGFxYfa?|8LnGZ-IfHFURluH> zT0El%_tb04o5zs0qoY-+h@Hb0rAqA@rb%gWZ7tZEevG}-2ZW~o)KjT`Wu7iSs%K5V zXa3>20-b79l-3jGUkz>B5rK`3BM30zr~toE)AN&Q+kgY55g5Xgz$qy8xEggvY0D%n Z+yFR2@FDuKr;z{v002ovPDHLkV1f_YhN%Dm diff --git a/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.ppm b/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract.ppm deleted file mode 100644 index 3b7c0fbe1e2cf06c2a552c2116887b1a96f89595..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2011 zcmb_cQBDFu44wVmQ%vF)CKAEG1^h66V7P)tVn_@cP!rwD%>nQbT*UfbJ1ha|giY*r z%S@+zZKqwPUlyhHOU?+WG@(U<&b}J!~wY+(^4tt zF7vcIsZUN^n&7d4w-Srf$!eE%iH8@IRCWS4*W$QvxRB-)B^gb(TJSJ>XkwcU^ z_@}>`kgS8p09KQ2{(CJe-+AuVMuNu%uHQQgIQ3eXL$X0{BzUZdDy+s1nHx67#bqR` zLzvU(lDRdjSBb~0j(OuJQM%yA>e6m~RpK%62&&+QZ`%WzuVANz!b~)DC^hKBX=1qIFRnSe{y;<4pQt7xtT!uyjcUHU^D(Ni?Lssy@xO6@uIImLKBK^DM Gm4siA3(7qJ diff --git a/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract_large.png b/contents/euclidean_algorithm/code/piet/subtract/euclidian_algorithm_subtract_large.png new file mode 100644 index 0000000000000000000000000000000000000000..423b717767cc9621701ebf8fe14ae06d7c7efc66 GIT binary patch literal 2473 zcmeAS@N?(olHy`uVBq!ia0y~yV9H@&U|hn%1{CQzR+$K-*pj^6U4S$Y{B+)352QE? zJR*x381$4un6YB1eHl=Yy~NYkmHiPHtGJAcruLV^KxJm0E{-7;x8B~^xbb$FK-u-4X%4XZki|&uz#Jv6Fy7E=m z_x(Slf91p5824ZQUMugp_u=c(+?U7AtL@_t+q=JfuKX`sB<{m*CWeH}CSC@I4U7y5 zHy9XLq!}21T!w>eV6Ff#2%y}C1ZD;hm%|LK3d99zf^r$scda^R_F=Wpk9V)PEkD3t z76108cvya1MBRgZ^Yww+x`h!&fh>X<1+)l<$whp(Vcd2mM6?&DFQ6>-=1?RnRCZuZQj>-itF z@AW_Y`Ox~{c%a+E)Da;Ca~hJFSiFZ6QZRQFEL)v5iTQcQ`1?-l_kk3h(E%e}14o_xQea{qy2x3=Ky)fdP*@v|#ao6qi_>G-u}$_J2PM-)I%c zSAG1yrnp${+~G=#{#Bn^sgMMKRzJv#y~Mmf1n8#|F3V+)KRSQB(4wfJ;dN>Mxz9i= z5(<%=M@dpsv;6RPOYGCcJ*8hhp0LaLZ+9TDy5gSLJoD`z*!2F*Fa7$}ivRgTn}3gM z=hr^|eTa==g9ZK+4GmbNcmkz+SmZ*T+F%?TDm>Rh{*4y@mzF(l$KP&tf1bNH^}6-T zzuf0%NB{UG_W%5@UsZG4KmSh2E9iCCu zd+v5$?#r+5wx(Z?zWs>3rg*Y7|GRHCYBB~7^CKqjwF9M3F{-4`XOrYCz9xlND$L*f zcwJeE=H4Im*LGThg7w{3n?7Z$b5u-~N7VoQy}0hsd83Dw$J6{7nZCU?wW4OK2b!N4 z{4m77Dxu_-S$4eqfxSE0?$=Yd$msTMHQp?Lv2t(f`h5QN<;719On&v|^*vB1U8PFi zeYtAZlLOyv%ciz}G?SgXy?uSYw|)hG{6n#QhjzB!Z|MG?9$UNDzg+I&{q1?rKVEo! z_MSd9eQ5jP=)6x3_YQqtcYa&r?|E~t`+t)!{`z&>|3Bv*7hba#-nZ{@N8jfy)GCF2 z!mp~Z*PZQaj(-(gS`zo?<%~B+7Wco{le_Irk@cSD$+7PXQ?6Ifd^);Tjj|&=hx|Vpjs#2jPU{I8)NTyYS(JP z`)`LbJed99$DS`=-wK~ycx%_<&(!uqRem^QLw?g^UF(8*+5f3mJjI44OEWYqpSEt{ fxjrhE^ZyumKfRj9R{iTLsKw>!>gTe~DWM4fu)h8s literal 0 HcmV?d00001 From 516331237d78bb3c9be7dbd92e60600d9898ee6e Mon Sep 17 00:00:00 2001 From: Thijs Raymakers Date: Sun, 7 Oct 2018 16:08:26 +0200 Subject: [PATCH 10/13] Add the images to the euclidian algorithm page --- contents/euclidean_algorithm/euclidean_algorithm.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contents/euclidean_algorithm/euclidean_algorithm.md b/contents/euclidean_algorithm/euclidean_algorithm.md index ff05c7af9..ad84587ff 100644 --- a/contents/euclidean_algorithm/euclidean_algorithm.md +++ b/contents/euclidean_algorithm/euclidean_algorithm.md @@ -63,6 +63,8 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two [import:25-40, lang="LOLCODE"](code/lolcode/euclid.lol) {% sample lang="bash" %} [import:24-38, lang="bash"](code/bash/euclid.bash) +{% sample lang="piet" %} +> ![](code/piet/subtract/euclidian_algorithm_subtract_large.png) ![](code/piet/subtract/euclidian_algorithm_subtract.png) {% endmethod %} 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 [import:9-23, lang="LOLCODE"](code/lolcode/euclid.lol) {% sample lang="bash" %} [import:10-22, lang="bash"](code/bash/euclid.bash) +{% sample lang="piet" %} +> ![](code/piet/mod/euclidian_algorithm_mod_large.png) ![](code/piet/mod/euclidian_algorithm_mod.png) {% endmethod %} 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: [import, lang="LOLCODE"](code/lolcode/euclid.lol) {% sample lang="bash" %} [import, lang="bash"](code/bash/euclid.bash) +{% sample lang="piet" %} +> ![](code/piet/subtract/euclidian_algorithm_subtract_large.png) ![](code/piet/subtract/euclidian_algorithm_subtract.png) + +> ![](code/piet/mod/euclidian_algorithm_mod_large.png) ![](code/piet/mod/euclidian_algorithm_mod.png) {% endmethod %}