File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
contents/bogo_sort/code/go Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -61,3 +61,5 @@ Bendik Samseth
61
61
Trashtalk
62
62
<br >
63
63
Cyrus Burt
64
+ <br >
65
+ Christopher Milan
Original file line number Diff line number Diff line change
1
+ // Submitted by Christopher Milan (christopherm99)
2
+
3
+ package main
4
+
5
+ import (
6
+ "fmt"
7
+ "math/rand"
8
+ "time"
9
+ )
10
+
11
+ func shuffle (a []int ) []int {
12
+ rand .Seed (time .Now ().UnixNano ())
13
+ for i := len (a ) - 1 ; i > 0 ; i -- {
14
+ j := rand .Intn (i + 1 )
15
+ a [i ], a [j ] = a [j ], a [i ]
16
+ }
17
+ return a
18
+ }
19
+
20
+ func is_sorted (a []int ) bool {
21
+ for i := 0 ; i < len (a )- 1 ; i ++ {
22
+ if a [i + 1 ] < a [i ] {
23
+ return false
24
+ }
25
+ }
26
+ return true
27
+ }
28
+
29
+ func bogo_sort (a * []int ) {
30
+ for ! is_sorted (* a ) {
31
+ * a = shuffle (* a )
32
+ }
33
+ }
34
+
35
+ func main () {
36
+ a := []int {1 , 3 , 4 , 2 }
37
+ bogo_sort (& a )
38
+ fmt .Println (a )
39
+ }
You can’t perform that action at this time.
0 commit comments