RosettaCodeData/Task/Van-der-Corput-sequence/Sidef/van-der-corput-sequence.sidef

16 lines
357 B
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}
 
for base in (2..5) {
var seq = 10.of {|i| vdc([i], base) }
"base %d: %s\n".printf(base, seq.map{|n| "%.4f" % n}.join(', '))
}