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

Published on 12 May 2024 09:40 PM

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

Source code in the raku programming language

sub is-pernicious(Int $n --> Bool) {
    is-prime [+] $n.base(2).comb;
}

say (grep &is-pernicious, 0 .. *)[^25];
say grep &is-pernicious, 888_888_877 .. 888_888_888;


  

You may also check:How to resolve the algorithm Bitmap/Read an image through a pipe step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Roman numerals/Decode step by step in the Rust programming language
You may also check:How to resolve the algorithm Long multiplication step by step in the Julia programming language
You may also check:How to resolve the algorithm Guess the number step by step in the R programming language
You may also check:How to resolve the algorithm Price fraction step by step in the Kotlin programming language