Skip to content

Commit 2fa064d

Browse files
PaddyKejiegillet
authored andcommitted
Add Bogo sort in R (#536)
* add Bogo sort in R * added newline at the end
1 parent 4f8728f commit 2fa064d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

contents/bogo_sort/bogo_sort.md

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ In code, it looks something like this:
6363
[import:20-24, lang:"lisp"](code/clisp/bogo-sort.lisp)
6464
{% sample lang="crystal" %}
6565
[import:10-14, lang:"crystal"](code/crystal/bogo.cr)
66+
{% sample lang="r" %}
67+
[import:1-6, lang:"r"](code/r/bogo_sort.r)
6668
{% endmethod %}
6769

6870
That's it.
@@ -125,6 +127,8 @@ We are done here!
125127
[import, lang:"lisp"](code/clisp/bogo-sort.lisp)
126128
{% sample lang="crystal" %}
127129
[import, lang:"crystal"](code/crystal/bogo.cr)
130+
{% sample lang="r" %}
131+
[import, lang:"r"](code/r/bogo_sort.r)
128132
{% endmethod %}
129133

130134

contents/bogo_sort/code/r/bogo_sort.r

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
bogo_sort <- function(a) {
2+
while(is.unsorted(a)) {
3+
a <- sample(a)
4+
}
5+
return(a)
6+
}
7+
8+
test <- c(20, -3, 50, 1, -6, 59)
9+
10+
print("unsorted list")
11+
print(test)
12+
13+
print("sorted list")
14+
print(bogo_sort(test))
15+

0 commit comments

Comments
 (0)