Skip to content

Instantly share code, notes, and snippets.

@pjvds
Created August 30, 2014 19:36
Show Gist options
  • Save pjvds/cd2b31ec62e6572eb7e6 to your computer and use it in GitHub Desktop.
Save pjvds/cd2b31ec62e6572eb7e6 to your computer and use it in GitHub Desktop.
func sleepSort(input []int) []int {
length := len(input)
sorting := make(chan int)
for i := 0; i < length; i++ {
go func(n int) {
time.Sleep(time.Duration(n) * time.Millisecond * slack)
sorting <- n
}(input[i])
}
output := make([]int, length, length)
for i := 0; i < length; i++ {
output[i] = <-sorting
}
return output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment