2 USING: math math.parser sequences sequences.private kernel
5 : clear-flags ( step i seq -- )
9 f 2over set-nth-unsafe [ over + ] dip clear-flags
10 ] if ; inline recursive
12 : (nsieve) ( count i seq -- count )
15 over dup 2 * pick clear-flags
16 rot 1+ -rot ! increment count
17 ] when [ 1+ ] dip (nsieve)
20 ] if ; inline recursive
22 : nsieve ( m -- count )
23 0 2 rot 1+ t <array> (nsieve) ;
26 [ "Primes up to " % dup # " " % nsieve # ] "" make print ;
28 : nsieve-main ( n -- )
29 dup 2^ 10000 * nsieve.
30 dup 1 - 2^ 10000 * nsieve.
31 2 - 2^ 10000 * nsieve. ;
33 : nsieve-main* ( -- ) 9 nsieve-main ;