File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,8 @@ In code, it looks something like this:
61
61
[ import:93-113, lang:"asm-x64"] ( code/asm-x64/bogo_sort.s )
62
62
{% sample lang="lisp" %}
63
63
[ import:20-24, lang:"lisp"] ( code/clisp/bogo-sort.lisp )
64
+ {% sample lang="crystal" %}
65
+ [ import:10-14, lang:"crystal"] ( code/crystal/bogo.cr )
64
66
{% endmethod %}
65
67
66
68
That's it.
@@ -121,6 +123,8 @@ We are done here!
121
123
[ import, lang:"asm-x64"] ( code/asm-x64/bogo_sort.s )
122
124
{% sample lang="lisp" %}
123
125
[ import, lang:"lisp"] ( code/clisp/bogo-sort.lisp )
126
+ {% sample lang="crystal" %}
127
+ [ import, lang:"crystal"] ( code/crystal/bogo.cr )
124
128
{% endmethod %}
125
129
126
130
Original file line number Diff line number Diff line change
1
+ def is_sorted ?(a)
2
+ 0 .upto(a.size - 2 ) do |i |
3
+ if a[i] > a[i + 1 ]
4
+ return false
5
+ end
6
+ end
7
+ true
8
+ end
9
+
10
+ def bogo_sort !(a)
11
+ while ! is_sorted?(a)
12
+ a.shuffle!
13
+ end
14
+ end
15
+
16
+ def main
17
+ a = [1.0 , 3.0 , 2.0 , 4.0 ]
18
+ bogo_sort!(a)
19
+ puts a
20
+ end
21
+
22
+ main
You can’t perform that action at this time.
0 commit comments