Created
June 17, 2011 02:50
-
-
Save zliang-min/1030765 to your computer and use it in GitHub Desktop.
sleep sort, idea from http://dis.4chan.org/read/prog/1295544154
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
def sleep_sort(a) | |
result = [] | |
a.map { |e| Thread.new { sleep e; result << e } }.each { |t| t.join } | |
result | |
end | |
puts sleep_sort([7, 5, 8, 6, 4, 9, 2, 3, 1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment