Skip to content

Instantly share code, notes, and snippets.

@larryv
Created July 6, 2012 01:15
Show Gist options
  • Save larryv/3057432 to your computer and use it in GitHub Desktop.
Save larryv/3057432 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby1.9
def merge_sort(a)
return a if a.length <= 1
l = (merge_sort(a[0...(a.length / 2)]) << Float::INFINITY).each
r = (merge_sort(a[(a.length / 2)...a.length]) << Float::INFINITY).each
Array.new(a.length) {|i| l.peek < r.peek ? l.next : r.next}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment