How to resolve the algorithm Pernicious numbers step by step in the Quackery programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Pernicious numbers step by step in the Quackery programming language

Table of Contents

Problem Statement

A   pernicious number   is a positive integer whose   population count   is a prime. The   population count   is the number of   ones   in the binary representation of a non-negative integer.

22   (which is   10110   in binary)   has a population count of   3,   which is prime,   and therefore
22   is a pernicious number.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Pernicious numbers step by step in the Quackery programming language

Source code in the quackery programming language

  [ $ "rosetta/seive.qky" loadfile 
    $ "rosetta/popcount.qky" loadfile ] now!

  ( i.e. using the code at                                     )
  ( http://rosettacode.org/wiki/Sieve_of_Eratosthenes and      )
  ( http://rosettacode.org/wiki/Population_count               )

  29 eratosthenes ( Precompute as many primes as are required  )
                  ( for the task. 888,888,888 is a 30 bit      )
                  ( number less than (2^30)-1 so  primes up to )
                  ( 29 will suffice.                           )

  [ 1+ over - times
      [ dup i^ +
        dup popcount
        isprime iff
          [ echo sp ]
        else drop ]
    drop ]                    is perniciousrange   ( n n -->   )

  25 echopopwith isprime cr
 
  888888877 888888888 perniciousrange cr

  

You may also check:How to resolve the algorithm Conditional structures step by step in the HicEst programming language
You may also check:How to resolve the algorithm Stack step by step in the AWK programming language
You may also check:How to resolve the algorithm Collections step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Number reversal game step by step in the Inform 7 programming language
You may also check:How to resolve the algorithm Loops/Infinite step by step in the Phixmonti programming language