Skip to content

Instantly share code, notes, and snippets.

@nickserv
Last active October 13, 2015 21:08
Show Gist options
  • Save nickserv/4256138 to your computer and use it in GitHub Desktop.
Save nickserv/4256138 to your computer and use it in GitHub Desktop.
Bogo Sort in Ruby
class Array
def in_order?
(0..length-2).none? { |i| self[i] > self[i+1] }
end
def bogo_sort
copy = self.dup
copy.shuffle! until copy.in_order?
copy
end
end
test_array = []
5.times { test_array << rand(10) }
p test_array.bogo_sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment