Created
August 18, 2012 16:56
-
-
Save chrishunt/3388360 to your computer and use it in GitHub Desktop.
Sleep Sort
This file contains 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(*nums) | |
sorted = [] | |
nums.map do |n| | |
Thread.new { sleep n; sorted << n } | |
end.map(&:join) | |
sorted | |
end | |
sleep_sort 3, 1, 4, 2 #=> [1, 2, 3, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment