File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ In code, it looks something like this:
41
41
[ import:11-16, lang:"php"] ( code/php/bogo_sort.php )
42
42
{% sample lang="nim" %}
43
43
[ import:16-18, lang:"nim"] ( code/nim/bogo_sort.nim )
44
+ {% sample lang="ruby" %}
45
+ [ import:12-16, lang:"ruby"] ( code/ruby/bogo.rb )
44
46
{% endmethod %}
45
47
46
48
That's it.
@@ -81,6 +83,8 @@ We are done here!
81
83
[ import, lang:"php"] ( code/php/bogo_sort.php )
82
84
{% sample lang="nim" %}
83
85
[ import, lang:"nim"] ( code/nim/bogo_sort.nim )
86
+ {% sample lang="ruby" %}
87
+ [ import, lang:"ruby"] ( code/ruby/bogo.rb )
84
88
{% endmethod %}
85
89
86
90
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env ruby
2
+
3
+ def is_sorted ( a )
4
+ for i in 0 ...a . length -1
5
+ if a [ i +1 ] < a [ i ]
6
+ return false
7
+ end
8
+ end
9
+ return true
10
+ end
11
+
12
+ def bogo_sort ( a )
13
+ while !is_sorted ( a )
14
+ a . shuffle!
15
+ end
16
+ end
17
+
18
+ def main ( )
19
+ a = [ 1 , 1 , 0 , 3 , 7 ]
20
+
21
+ puts ( "Unsorted" )
22
+ print ( a )
23
+
24
+ bogo_sort ( a )
25
+
26
+ puts ( "\n \n Sorted" )
27
+ print ( a )
28
+ end
29
+
30
+ main ( )
31
+
You can’t perform that action at this time.
0 commit comments