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

Published on 12 May 2024 09:40 PM
#J

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

Source code in the j programming language

ispernicious=: 1 p: +/"1@#:


   25{.I.ispernicious i.100
3 5 6 7 9 10 11 12 13 14 17 18 19 20 21 22 24 25 26 28 31 33 34 35 36

   thru=: <. + i.@(+*)@-~
   (#~ ispernicious) 888888877 thru 888888888
888888877 888888878 888888880 888888883 888888885 888888886


  

You may also check:How to resolve the algorithm String case step by step in the Elm programming language
You may also check:How to resolve the algorithm Rock-paper-scissors step by step in the BASIC programming language
You may also check:How to resolve the algorithm Balanced ternary step by step in the Tcl programming language
You may also check:How to resolve the algorithm Word wrap step by step in the IS-BASIC programming language
You may also check:How to resolve the algorithm Sudan function step by step in the Phix programming language