scope /* show members of the van der Corput sequence in various bases * translated from the C sample */ # returns the numerator and denominator of the nth member of the van der Corput sequence # in the specified base local proc vc( nth :: number, base :: number ) local p, q, n := 0, 1, nth; while n <> 0 do p *:= base; p +:= n mod base; q *:= base; n \:= base od; # return the numerator and denominator reduced by their gcd local num, denom := p, q; q := numtheory.gcd( p, q ); return num \ q, denom \ q end; # task for b from 2 to 5 do printf( "base %d:", b ); for i from 0 to 9 do local n, d := vc( i, b ); if n <> 0 then printf( " %d/%d", n, d ) else printf( " 0" ) fi od; io.write( "\n" ) od epocs