Skip to content

Instantly share code, notes, and snippets.

@jcazevedo
Created May 21, 2012 15:51
Show Gist options
  • Save jcazevedo/2762999 to your computer and use it in GitHub Desktop.
Save jcazevedo/2762999 to your computer and use it in GitHub Desktop.
SleepSort in Scala
import scala.actors.Future
import scala.actors.Futures._
object SleepSort {
def main(args: Array[String]) = {
var sorted = List[Int]()
var futures = for (a <- args) yield future {
Thread.sleep(a.toInt * 1000)
sorted :::= List(a.toInt)
a.toInt
}
// Don't wait more than a minute
awaitAll(60000, futures:_*)
print(sorted.reverse)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment