mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-17 06:11:43 +01:00
9e911b19d6
This removes the following warning which `ruby -w` emits: > bogo_sort.rb:8: warning: mismatched indentations at 'end' with 'def' at 2
18 lines
433 B
Ruby
18 lines
433 B
Ruby
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('')
|