#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Van_der_Corput_sequence
#

func vdc(value, base=2) {
    while (value[-1] > 0) {
        value.append(value[-1] / base -> int);
    }
    var (x, sum) = (1, 0);
    value.each { |i|
        sum += ((i % base) / (x *= base));
    }
    return sum;
}

2.to(5).each { |base|
    var seq = (9.range.map {|i| vdc([i], base) });
    "base %d: %s\n".printf(base, seq.map{|n| "%.4f" % n}.join(', '));
}
