Skip to content

Commit 60f89b3

Browse files
PaddyKejiegillet
authored andcommitted
Add Bogosort in Racket (#461)
1 parent 1b5f58e commit 60f89b3

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

contents/bogo_sort/bogo_sort.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ In code, it looks something like this:
5151
[import:10-12, lang:"factor"](code/factor/bogo_sort.factor)
5252
{% sample lang="f90" %}
5353
[import:24-32, lang:"fortran"](code/fortran/bogo.f90)
54+
{% sample lang="racket" %}
55+
[import:3-8, lang:"lisp"](code/racket/bogo_sort.rkt)
5456
{% sample lang="st" %}
5557
[import:2-6, lang:"st"](code/smalltalk/bogosort.st)
5658
{% endmethod %}
@@ -103,6 +105,8 @@ We are done here!
103105
[import, lang:"factor"](code/factor/bogo_sort.factor)
104106
{% sample lang="f90" %}
105107
[import, lang:"fortran"](code/fortran/bogo.f90)
108+
{% sample lang="racket" %}
109+
[import, lang:"lisp"](code/racket/bogo_sort.rkt)
106110
{% sample lang="st" %}
107111
[import, lang:"st"](code/smalltalk/bogosort.st)
108112
{% endmethod %}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#lang racket
2+
3+
(define (bogo_sort l)
4+
(if (is_sorted? l)
5+
l
6+
(bogo_sort (shuffle l))
7+
)
8+
)
9+
10+
(define (is_sorted? l)
11+
(if (> (length l) 1)
12+
(if (> (first l) (second l))
13+
false
14+
(is_sorted? (rest l))
15+
)
16+
true
17+
)
18+
)
19+
20+
(define unsorted_list '(20 -3 50 1 -6 59))
21+
(display "unsorted list: ")
22+
(displayln unsorted_list)
23+
(display "sorted list: ")
24+
(displayln (bogo_sort unsorted_list))

0 commit comments

Comments
 (0)