Skip to content

Commit c4cd16f

Browse files
jiegilletleios
authored andcommitted
Whitespace: added Euclidian algorithm (#415)
* Whitespace: added Euclidian algorithm * Euclid_mod was corrupted, replaced it * Added the end at the end of the file for gitbook formatting * Fixed sub method and added comments * Added comments to .md file
1 parent 1cff9f9 commit c4cd16f

File tree

7 files changed

+155
-0
lines changed

7 files changed

+155
-0
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ indent_size = 2
110110
indent_style = space
111111
indent_size = 4
112112

113+
# Whitespace
114+
[*.ws]
115+
indent_style = space
116+
indent_size = 0
117+
trim_trailing_whitespace = false
118+
insert_final_newline = false
119+
end_of_line = lf
120+
113121
# Emojicode
114122
[*.emojic]
115123
indent_style = space

book.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@
144144
"lang": "f90",
145145
"name": "Fortran90"
146146
},
147+
{
148+
"lang": "ws",
149+
"name": "Whitespace"
150+
},
147151
{
148152
"lang": "scala",
149153
"name": "Scala"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Euclidian algorithm modulo method.
2+
Enter two positive integers.
3+
4+
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
The
28+
end.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Reading the input: a, b
2+
[SPACE][SPACE][SPACE][LF] push 0
3+
[SPACE][SPACE][SPACE][TAB][LF] push 1
4+
[TAB][LF][TAB][TAB] readi
5+
[TAB][LF][TAB][TAB] readi
6+
7+
Loop: a, b => b, a%b
8+
[LF][SPACE][SPACE][LF] label_0:
9+
[SPACE][SPACE][SPACE][LF] push 0
10+
[TAB][TAB][TAB] retrieve
11+
[SPACE][LF][SPACE] dup
12+
[LF][TAB][SPACE][TAB][LF] jmp zero label_1
13+
[SPACE][SPACE][SPACE][TAB][LF] push 1
14+
[TAB][TAB][TAB] retrieve
15+
[SPACE][LF][TAB] swap
16+
[TAB][SPACE][TAB][TAB] mod
17+
[SPACE][SPACE][SPACE][LF] push 0
18+
[TAB][TAB][TAB] retrieve
19+
[SPACE][SPACE][SPACE][TAB][LF] push 1
20+
[SPACE][LF][TAB] swap
21+
[TAB][TAB][SPACE] store
22+
[SPACE][SPACE][SPACE][LF] push 0
23+
[SPACE][LF][TAB] swap
24+
[TAB][TAB][SPACE] store
25+
[LF][SPACE][LF][LF] jmp label_0
26+
27+
Exit when b=0
28+
[LF][SPACE][SPACE][TAB][LF] label_1:
29+
[SPACE][SPACE][SPACE][TAB][LF] push 1
30+
[TAB][TAB][TAB] retrieve
31+
[TAB][LF][SPACE][TAB] printi
32+
[LF][LF][LF][LF] end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Euclidian algorithm subtraction method.
2+
Enter two positive integers.
3+
4+
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
The
36+
end.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Reading the input: a, b
2+
[SPACE][SPACE][SPACE][LF] push 0
3+
[SPACE][SPACE][SPACE][TAB][LF] push 1
4+
[TAB][LF][TAB][TAB] readi
5+
[TAB][LF][TAB][TAB] readi
6+
7+
Loop: a, b => a, b-a
8+
[LF][SPACE][SPACE][LF] label_0:
9+
[SPACE][SPACE][SPACE][LF] push 0
10+
[TAB][TAB][TAB] retrieve
11+
[SPACE][SPACE][SPACE][TAB][LF] push 1
12+
[TAB][TAB][TAB] retrieve
13+
[TAB][SPACE][SPACE][TAB] sub
14+
[SPACE][LF][SPACE] dup
15+
[LF][TAB][SPACE][TAB][LF] jmp zero label_1
16+
[SPACE][LF][SPACE] dup
17+
[LF][TAB][TAB][TAB][SPACE][LF] jmp neg label_2
18+
[SPACE][SPACE][SPACE][LF] push 0
19+
[SPACE][LF][TAB] swap
20+
[TAB][TAB][SPACE] store
21+
[LF][SPACE][LF][LF] jmp label_0
22+
23+
Exit when a=b
24+
[LF][SPACE][SPACE][TAB][LF] label_1:
25+
[SPACE][SPACE][SPACE][LF] push 0
26+
[TAB][TAB][TAB] retrieve
27+
[TAB][LF][SPACE][TAB] printi
28+
[LF][LF][LF] end
29+
30+
If a>b: a, b => a-b, b
31+
[LF][SPACE][SPACE][TAB][SPACE][LF] label_2:
32+
[SPACE][SPACE][SPACE][LF] push 0
33+
[SPACE][LF][TAB] swap
34+
[TAB][SPACE][SPACE][TAB] sub
35+
[SPACE][SPACE][SPACE][TAB][LF] push 1
36+
[SPACE][LF][TAB] swap
37+
[TAB][TAB][SPACE] store
38+
[LF][SPACE][LF][LF] jmp label_0

contents/euclidean_algorithm/euclidean_algorithm.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two
4141
[import:13-24, lang="nim"](code/nim/euclid_algorithm.nim)
4242
{% sample lang="f90" %}
4343
[import:1-19, lang="fortran"](code/fortran/euclidean.f90)
44+
{% sample lang="ws" %}
45+
[import, lang="whitespace"](code/whitespace/euclidian_sub.ws)
4446
{% sample lang="scala" %}
4547
[import:3-8, lang="scala"](code/scala/euclidean.scala)
4648
{% sample lang="racket" %}
@@ -96,6 +98,8 @@ Modern implementations, though, often use the modulus operator (%) like so
9698
[import:1-11, lang="nim"](code/nim/euclid_algorithm.nim)
9799
{% sample lang="f90" %}
98100
[import:21-34, lang="fortran"](code/fortran/euclidean.f90)
101+
{% sample lang="ws" %}
102+
[import, lang="whitespace"](code/whitespace/euclidian_mod.ws)
99103
{% sample lang="scala" %}
100104
[import:10-14, lang="scala"](code/scala/euclidean.scala)
101105
{% sample lang="racket" %}
@@ -156,6 +160,11 @@ The Euclidean Algorithm is truly fundamental to many other algorithms throughout
156160
[import, lang="nim" %](code/nim/euclid_algorithm.nim)
157161
{% sample lang="f90" %}
158162
[import, lang="fortran"](code/fortran/euclidean.f90)
163+
{% sample lang="ws" %}
164+
Here is a readable version of the algorithms with comments. First, subtraction method:
165+
[import, lang="whitespace"](code/whitespace/euclidian_sub_comments.ws)
166+
and modulo method:
167+
[import, lang="whitespace"](code/whitespace/euclidian_mod_comments.ws)
159168
{% sample lang="scala" %}
160169
[import, lang="scala"](code/scala/euclidean.scala)
161170
{% sample lang="racket" %}

0 commit comments

Comments
 (0)