mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-11-16 19:50:00 +01:00
24 lines
416 B
Ruby
24 lines
416 B
Ruby
class Array
|
|
def columns
|
|
x = map(&:length).max
|
|
Array.new(x) do |row|
|
|
Array.new(length) { |column| self[column][row] }.compact
|
|
end
|
|
end
|
|
end
|
|
|
|
def bead_sort(array)
|
|
array
|
|
.map { |element| [1] * element }
|
|
.columns
|
|
.columns
|
|
.map(&:length)
|
|
.reverse
|
|
end
|
|
|
|
if $0 == __FILE__
|
|
puts 'Enter a list of numbers separated by space'
|
|
|
|
list = gets.split.map(&:to_i)
|
|
p bead_sort(list)
|
|
end
|