diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index e840617b6..526c941c6 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,4 +1,4 @@ -This file lists everyone, who contributed to this repo and wanted to show up here. If you're looking for information on contribution, please check the `CONTRIBUTING.md` out. +This file lists everyone, who contributed to this repo and wanted to show up here. If you're looking for information on contribution, please check the `CONTRIBUTING.md` out. # Contributors @@ -38,3 +38,4 @@ - PaddyKe - nic-hartley - crafter312 +- Christopher Milan \ No newline at end of file diff --git a/contents/bogo_sort/code/go/main.go b/contents/bogo_sort/code/go/main.go new file mode 100644 index 000000000..a8297fc50 --- /dev/null +++ b/contents/bogo_sort/code/go/main.go @@ -0,0 +1,38 @@ +// Submitted by Christopher Milan (christopherm99) + +package main + +import ( + "fmt" + "math/rand" + "time" +) + +func shuffle(a *[]int) { + for i := len(*a) - 1; i > 0; i-- { + j := rand.Intn(i + 1) + (*a)[i], (*a)[j] = (*a)[j], (*a)[i] + } +} + +func isSorted(a []int) bool { + for i := 0; i < len(a)-1; i++ { + if a[i+1] < a[i] { + return false + } + } + return true +} + +func bogoSort(a *[]int) { + for !isSorted(*a) { + shuffle(a) + } +} + +func main() { + rand.Seed(time.Now().UnixNano()) + a := []int{1, 3, 4, 2} + bogoSort(&a) + fmt.Println(a) +}