Author: | slava |
---|---|
Mode: | factor |
Date: | Sat, 27 Sep 2008 14:34:50 |
: init-sieve ( n -- xs ) [ 1 ] B{ } replicate-as 0 over set-first 0 over set-second ; inline : set-all ( elt indices seq -- ) swap [ swap set-nth ] with with each ; inline : multiples ( i n -- range ) over [ 2 * ] [ 1 - ] [ ] tri* <range> ; :: nsieve ( n -- pi(n) ) [let | xs [ n init-sieve ] | xs [| i | 1 = [ 0 i n multiples xs set-all ] when ] each-index xs sum ] ;