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

Published on 12 May 2024 09:40 PM

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

Source code in the plain programming language

To decide if a number is pernicious:
Find a population count of the number.
If the population count is prime, say yes.
Say no.

To find a population count of a number:
Privatize the number.
Loop.
If the number is 0, exit.
Bitwise and the number with the number minus 1.
Bump the population count.
Repeat.

To run:
Start up.
Show the first twenty-five pernicious numbers.
Show the pernicious numbers between 888888877 and 888888888.
Wait for the escape key.
Shut down.

To show the first twenty-five pernicious numbers:
Put 0 into a number.
Put 0 into a pernicious number count.
Loop.
If the pernicious number count is greater than 24, write "" on the console; exit.
If the number is pernicious, show the number; bump the pernicious number count.
Bump the number.
Repeat.

To show a number:
Convert the number to a string.
Write the string then " " on the console without advancing.

To show the pernicious numbers between a number and another number:
Privatize the number.
Subtract 1 from the number.
Loop.
If the number is past the other number, exit.
If the number is pernicious, show the number.
Repeat.

  

You may also check:How to resolve the algorithm Determine if a string has all the same characters step by step in the Plain English programming language
You may also check:How to resolve the algorithm Literals/Integer step by step in the Plain English programming language
You may also check:How to resolve the algorithm Check that file exists step by step in the Plain English programming language
You may also check:How to resolve the algorithm Execute a system command step by step in the Plain English programming language
You may also check:How to resolve the algorithm Loops/Downward for step by step in the Plain English programming language