File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,8 @@ In code, it looks something like this:
59
59
[ import:93-113, lang:"asm-x64"] ( code/asm-x64/bogo_sort.s )
60
60
{% sample lang="lisp" %}
61
61
[ import:20-24, lang:"lisp"] ( code/lisp/bogo-sort.lisp )
62
+ {% sample lang="crystal" %}
63
+ [ import:17-21, lang:"crystal"] ( code/crystal/bogo.cr )
62
64
{% endmethod %}
63
65
64
66
That's it.
@@ -117,6 +119,8 @@ We are done here!
117
119
[ import, lang:"asm-x64"] ( code/asm-x64/bogo_sort.s )
118
120
{% sample lang="lisp" %}
119
121
[ import, lang:"lisp"] ( code/lisp/bogo-sort.lisp )
122
+ {% sample lang="crystal" %}
123
+ [ import, lang:"crystal"] ( code/crystal/bogo.cr )
120
124
{% endmethod %}
121
125
122
126
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 shuffle !(a)
11
+ 0 .upto(a.size - 2 ) do |i |
12
+ r = rand(i..a.size - 1 )
13
+ a[i], a[r] = a[r], a[i]
14
+ end
15
+ end
16
+
17
+ def bogo_sort !(a)
18
+ while ! is_sorted?(a)
19
+ shuffle!(a)
20
+ end
21
+ end
22
+
23
+ def main
24
+ a = [1.0 , 3.0 , 2.0 , 4.0 ]
25
+ bogo_sort!(a)
26
+ puts a
27
+ end
28
+
29
+ main
You can’t perform that action at this time.
0 commit comments