How to resolve the algorithm De Polignac numbers step by step in the Raku programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm De Polignac numbers step by step in the Raku programming language
Table of Contents
Problem Statement
Alphonse de Polignac, a French mathematician in the 1800s, conjectured that every positive odd integer could be formed from the sum of a power of 2 and a prime number. He was subsequently proved incorrect. The numbers that fail this condition are now known as de Polignac numbers. Technically 1 is a de Polignac number, as there is no prime and power of 2 that sum to 1. De Polignac was aware but thought that 1 was a special case. However. 127 is also fails that condition, as there is no prime and power of 2 that sum to 127. As it turns out, de Polignac numbers are not uncommon, in fact, there are an infinite number of them.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm De Polignac numbers step by step in the Raku programming language
Source code in the raku programming language
use List::Divvy;
use Lingua::EN::Numbers;
constant @po2 = (1..∞).map: 2 ** *;
my @dePolignac = lazy 1, |(2..∞).hyper.map(* × 2 + 1).grep: -> $n { all @po2.&upto($n).map: { !is-prime $n - $_ } };
say "First fifty de Polignac numbers:\n" ~ @dePolignac[^50]».&comma».fmt("%5s").batch(10).join: "\n";
say "\nOne thousandth: " ~ comma @dePolignac[999];
say "\nTen thousandth: " ~ comma @dePolignac[9999];
You may also check:How to resolve the algorithm Rosetta Code/Fix code tags step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Hello world/Standard error step by step in the Swift programming language
You may also check:How to resolve the algorithm Pseudo-random numbers/Splitmix64 step by step in the Go programming language
You may also check:How to resolve the algorithm Variadic function step by step in the Golo programming language
You may also check:How to resolve the algorithm Loops/Infinite step by step in the C programming language