Skip to content

Commit

Permalink
Add Bogo sort in R (algorithm-archivists#536)
Browse files Browse the repository at this point in the history
* add Bogo sort in R

* added newline at the end
  • Loading branch information
PaddyKe authored and jiegillet committed Oct 30, 2018
1 parent 4f8728f commit 2fa064d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions contents/bogo_sort/bogo_sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ In code, it looks something like this:
[import:20-24, lang:"lisp"](code/clisp/bogo-sort.lisp)
{% sample lang="crystal" %}
[import:10-14, lang:"crystal"](code/crystal/bogo.cr)
{% sample lang="r" %}
[import:1-6, lang:"r"](code/r/bogo_sort.r)
{% endmethod %}

That's it.
Expand Down Expand Up @@ -125,6 +127,8 @@ We are done here!
[import, lang:"lisp"](code/clisp/bogo-sort.lisp)
{% sample lang="crystal" %}
[import, lang:"crystal"](code/crystal/bogo.cr)
{% sample lang="r" %}
[import, lang:"r"](code/r/bogo_sort.r)
{% endmethod %}


Expand Down
15 changes: 15 additions & 0 deletions contents/bogo_sort/code/r/bogo_sort.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
bogo_sort <- function(a) {
while(is.unsorted(a)) {
a <- sample(a)
}
return(a)
}

test <- c(20, -3, 50, 1, -6, 59)

print("unsorted list")
print(test)

print("sorted list")
print(bogo_sort(test))

0 comments on commit 2fa064d

Please sign in to comment.