#!/usr/bin/ruby

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

func stooge(x, i, j) {
    x[j] < x[i] && (
        x[i, j] = x[j, i];
    );
 
    j-i > 1 && do {
        var t = ((j - i + 1) / 3);
        stooge(x, i,     j - t);
        stooge(x, i + t, j    );
        stooge(x, i,     j - t);
    };

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