2016-08-12 18:41:35 +02:00
|
|
|
class Array
|
2020-05-14 04:15:53 +02:00
|
|
|
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
|
2020-11-01 12:43:07 +01:00
|
|
|
return true
|
|
|
|
end
|
2020-05-14 04:15:53 +02:00
|
|
|
def bogosort
|
|
|
|
### randomly shuffles until sorted
|
|
|
|
self.shuffle! until self.sorted?
|
|
|
|
return self #return sorted array
|
|
|
|
end
|
2016-08-12 18:41:35 +02:00
|
|
|
end
|
|
|
|
|
2020-11-01 12:58:09 +01:00
|
|
|
puts "Enter a list of numbers separated by space"
|
2016-08-12 18:41:35 +02:00
|
|
|
str = gets.chomp.split('')
|
|
|
|
puts str.bogosort.join('')
|