Skip to content

Instantly share code, notes, and snippets.

@mattyw
Created December 29, 2013 20:29
Show Gist options
  • Save mattyw/8174462 to your computer and use it in GitHub Desktop.
Save mattyw/8174462 to your computer and use it in GitHub Desktop.
// Sleep sort
// http://archives.cazzaserver.com/SleepSortWiki/SleepSort.html
package main
import (
"fmt"
"time"
)
func sorter(c chan int, value int) {
time.Sleep(time.Millisecond * time.Duration(value))
c <- value
}
func main() {
unsorted := []int{2, 1, 4, 3}
c := make(chan int)
for _, x := range unsorted {
go sorter(c, x)
}
sorted := []int{}
for _ = range unsorted {
v := <-c
sorted = append(sorted, v)
}
fmt.Println(sorted)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment