func primes(n) /* DOCUMENT primes(n) Prime number generation by outer product. */ { return where(2 == (0 == (v = indgen(n))(-,)%v)(sum,)); } |
func sieve(n) /* DOCUMENT sieve(n) Prime number generation by sieve of Eratosthenes. */ { tbl = array(1, n); tbl(1) = 0; for (i = 2; i + i <= n; ++i) { if (tbl(i)) tbl(indgen(i + i : n : i)) = 0; } return where(tbl > 0); } |