#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort
#

func comb_sort(Array arr) {
    var gap = arr.len;
    var swaps = true;
    while (gap > 1 || swaps) {
        gap.div!(1.25).int! if (gap > 1);
        swaps = false;
        range(0, arr.end - gap).each { |i|
            if (arr[i] > arr[i+gap]) {
                arr[i, i+gap] = arr[i+gap, i];
                swaps = true;
            }
        }
    };
    return arr;
};

var numbers = [7,6,5,9,8,4,3,1,2,0];
say comb_sort(numbers);
 
var strs = ["John", "Kate", "Zerg", "Alice", "Joe", "Jane"];
say comb_sort(strs);
