def kth_digit(n, i) while(i > 1) n = n / 10 i = i - 1 end n % 10 end def radix_sort(a) max = a.max d = Math.log10(max).floor + 1 (1..d).each do |i| tmp = [] (0..9).each do |j| tmp[j] = [] end a.each do |n| kth = kth_digit(n, i) tmp[kth] << n end a = tmp.flatten end return a end