In computer science, bogosort (also known as permutation sort, stupid sort, slowsort, shotgun sort, or monkey sort) is a highly inefficient sorting algorithm based on the generate and test paradigm. Two versions of this algorithm exist: a deterministic version that enumerates all permutations until it hits a sorted one, and a randomized version that randomly permutes its input.
class Array def sorted? ### goes thru array and checks if all elements are in order for i in 1...self.length return false if self[i-1] > self[i] end return true end def bogosort ### randomly shuffles until sorted self.shuffle! until self.sorted? return self #return sorted array end end puts "Enter a list of numbers seprated by space" str = gets.chomp.split('') puts str.bogosort.join('')