Pernicious numbers: Difference between revisions
Content added Content deleted
m (added highlighting.) |
(→{{header|Quackery}}: reused code from population count) |
||
Line 2,161: | Line 2,161: | ||
=={{header|Quackery}}== |
=={{header|Quackery}}== |
||
<lang Quackery> [ $ "rosetta/seive.qky" loadfile |
<lang Quackery> [ $ "rosetta/seive.qky" loadfile |
||
$ "rosetta/popcount.qky" loadfile ] now! |
|||
( i.e. using the code from ) |
( i.e. using the code from ) |
||
( http://rosettacode.org/wiki/Sieve_of_Eratosthenes |
( http://rosettacode.org/wiki/Sieve_of_Eratosthenes and ) |
||
( http://rosettacode.org/wiki/Population_count ) |
|||
29 eratosthenes ( Precompute as many primes as are required ) |
29 eratosthenes ( Precompute as many primes as are required ) |
||
Line 2,170: | Line 2,172: | ||
( number less than (2^30)-1 so primes up to ) |
( number less than (2^30)-1 so primes up to ) |
||
( 29 will suffice. ) |
( 29 will suffice. ) |
||
[ 0 swap |
|||
[ dup while |
|||
dup 1 & |
|||
rot + swap |
|||
1 >> |
|||
again ] |
|||
drop ] is bitcount ( n --> n ) |
|||
[ bitcount isprime ] is pernicious ( n --> b ) |
|||
[ 0 |
|||
[ over while |
|||
[ dup pernicious |
|||
if [ dup echo sp |
|||
dip [ 1 - ] ] |
|||
⚫ | |||
again ] |
|||
2drop ] is perniciousnumbers ( n --> ) |
|||
[ 1+ over - times |
[ 1+ over - times |
||
[ dup i^ + |
[ dup i^ + |
||
dup |
dup popcount |
||
⚫ | |||
[ echo sp ] |
[ echo sp ] |
||
else drop ] |
else drop ] |
||
drop ] is perniciousrange ( n n --> ) |
drop ] is perniciousrange ( n n --> ) |
||
25 echopopwith isprime cr |
|||
25 perniciousnumbers cr |
|||
⚫ | |||
⚫ | |||
{{out}} |
{{out}} |