Skip to content

Instantly share code, notes, and snippets.

@chrishunt
Created August 18, 2012 16:56
Show Gist options
  • Save chrishunt/3388360 to your computer and use it in GitHub Desktop.
Save chrishunt/3388360 to your computer and use it in GitHub Desktop.
Sleep Sort
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