How to resolve the algorithm Pernicious numbers step by step in the Icon and Unicon programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Pernicious numbers step by step in the Icon and Unicon 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 Icon and Unicon programming language

Source code in the icon programming language

link "factors"

procedure main(A)
    every writes((pernicious(seq())\25||" ") | "\n")
    every writes((pernicious(888888877 to 888888888)||" ") | "\n")
end

procedure pernicious(n)
    return (isprime(c1bits(n)),n)
end

procedure c1bits(n)
    c := 0
    while n > 0 do c +:= 1(n%2, n/:=2)
    return c
end


  

You may also check:How to resolve the algorithm Non-decimal radices/Input step by step in the OCaml programming language
You may also check:How to resolve the algorithm Time a function step by step in the Erlang programming language
You may also check:How to resolve the algorithm Speech synthesis step by step in the ZX Spectrum Basic programming language
You may also check:How to resolve the algorithm Loops/N plus one half step by step in the F# programming language
You may also check:How to resolve the algorithm Compare a list of strings step by step in the V (Vlang) programming language