Sieve of Eratosthenes: Difference between revisions
Content deleted Content added
→{{header|Quackery}}: isprime now returns false if passed an argument larger than that passed to eratosthenes |
|||
Line 15,187: | Line 15,187: | ||
number on the primes ancillary stack is set. |
number on the primes ancillary stack is set. |
||
Initially all the bits are set except for 0 and 1, |
Initially all the bits are set except for 0 and 1, |
||
which are not prime numbers by definition. |
which are not prime numbers by definition. |
||
"eratosthenes" unsets all bits above those specified |
|||
by it's argument. ) |
|||
[ bit ~ |
[ bit ~ |
||
Line 15,194: | Line 15,196: | ||
[ bit primes share & 0 != ] is isprime ( n --> b ) |
[ bit primes share & 0 != ] is isprime ( n --> b ) |
||
[ dup sqrt times |
[ dup dup sqrt times |
||
[ i^ 1+ |
[ i^ 1+ |
||
dup isprime if |
dup isprime if |
||
[ dup 2 ** |
[ dup 2 ** |
||
[ dup -composite |
[ dup -composite |
||
over + |
over + |
||
rot 2dup > |
rot 2dup > |
||
dip unrot until ] |
dip unrot until ] |
||
drop ] |
drop ] |
||
drop ] |
drop ] |
||
drop |
|||
⚫ | |||
1+ bit 1 - |
|||
primes take & |
|||
⚫ | |||
100 eratosthenes |
100 eratosthenes |