How to resolve the algorithm Pernicious numbers step by step in the Miranda programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Pernicious numbers step by step in the Miranda 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 Miranda programming language
Source code in the miranda programming language
main :: [sys_message]
main = [Stdout (lay (map show [first25, large]))]
first25 :: [num]
first25 = take 25 (filter pernicious [1..])
large :: [num]
large = filter pernicious [888888877..888888888]
pernicious :: num->bool
pernicious = prime . popcount
popcount :: num->num
popcount 0 = 0
popcount n = n mod 2 + popcount (n div 2)
prime :: num->bool
prime n = n >= 2 & and [n mod d ~= 0 | d<-[2..sqrt n]]
You may also check:How to resolve the algorithm Factorial step by step in the LLVM programming language
You may also check:How to resolve the algorithm Integer sequence step by step in the Sidef programming language
You may also check:How to resolve the algorithm Hough transform step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Multisplit step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Guess the number/With feedback (player) step by step in the Perl programming language