Created
May 21, 2012 15:51
-
-
Save jcazevedo/2762999 to your computer and use it in GitHub Desktop.
SleepSort in Scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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