Skip to content

Commit 8c78043

Browse files
JulianButt4cak3
Julian
authored andcommitted
Euclid algorithm in lolcode (#469)
1 parent c6ff7bb commit 8c78043

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ indent_size = 2
8080
indent_style = space
8181
indent_size = 2
8282

83+
# LOLCODE
84+
[*.lol]
85+
indent_style = space
86+
indent_size = 4
87+
8388
# Matlab
8489
[*.m]
8590
indent_style = space

book.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@
155155
{
156156
"lang": "emojic",
157157
"name": "Emojicode"
158+
},
159+
{
160+
"lang": "lolcode",
161+
"name": "LOLCODE"
158162
}
159163
]
160164
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
HAI 1.2
2+
HOW IZ I ABZ YR NUM
3+
DIFFRINT NUM AN BIGGR OF NUM AN 0, O RLY?
4+
YA RLY, FOUND YR DIFF OF 0 AN NUM
5+
NO WAI, FOUND YR NUM
6+
OIC
7+
IF U SAY SO
8+
9+
HOW IZ I UKLIDMOD YR NUM1 AN YR NUM2
10+
NUM1 R I IZ ABZ YR NUM1 MKAY
11+
NUM2 R I IZ ABZ YR NUM2 MKAY
12+
13+
IM IN YR LOOP
14+
BOTH SAEM NUM2 AN 0, O RLY?
15+
YA RLY, FOUND YR NUM1
16+
OIC
17+
18+
I HAS A TMP ITZ NUM2
19+
NUM2 R MOD OF NUM1 AN NUM2
20+
NUM1 R TMP
21+
IM OUTTA YR LOOP
22+
23+
IF U SAY SO
24+
25+
HOW IZ I UKLIDSUP YR NUM1 AN YR NUM2
26+
NUM1 R I IZ ABZ YR NUM1 MKAY
27+
NUM2 R EI IZ ABZ YR NUM2 MKAY
28+
29+
IM IN YR LOOP
30+
BOTH SAEM NUM1 AN NUM2, O RLY?
31+
YA RLY, FOUND YR NUM1
32+
OIC
33+
34+
DIFFRINT NUM1 AN SMALLR OF NUM1 AN NUM2, O RLY?
35+
YA RLY, NUM1 R DIFF OF NUM1 AN NUM2
36+
NO WAI, NUM2 R DIFF OF NUM2 AN NUM1
37+
OIC
38+
IM OUTTA YR LOOP
39+
40+
IF U SAY SO
41+
42+
I HAS A CHECK1 ITZ I IZ UKLIDMOD YR PRODUKT OF 64 AN 67 AN YR PRODUKT OF 64 AN 81 MKAY
43+
I HAS A CHECK2 ITZ I IZ UKLIDSUP YR PRODUKT OF 128 AN 12 AN YR PRODUKT OF 128 AN 77 MKAY
44+
45+
VISIBLE CHECK1
46+
VISIBLE CHECK2
47+
KTHXBYE

contents/euclidean_algorithm/euclidean_algorithm.md

Lines changed: 6 additions & 1 deletion
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="lolcode" %}
55+
[import:25-40, lang="LOLCODE"](code/lolcode/euclid.lol)
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="lolcode" %}
114+
[import:9-23, lang="LOLCODE"](code/lolcode/euclid.lol)
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,9 +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="lolcode" %}
181+
[import, lang="LOLCODE"](code/lolcode/euclid.lol)
176182
{% endmethod %}
177183

178-
179184
<script>
180185
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
181186
</script>

0 commit comments

Comments
 (0)