How to resolve the algorithm De Polignac numbers step by step in the Wren programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm De Polignac numbers step by step in the Wren 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 Wren programming language
Source code in the wren programming language
import "./math" for Int
import "./fmt" for Fmt
var pows2 = (0..19).map { |i| 1 << i }.toList
var dp = [1]
var dp1000
var dp10000
var count = 1
var n = 3
while (true) {
var found = false
for (pow in pows2) {
if (pow > n) break
if (Int.isPrime(n-pow)) {
found = true
break
}
}
if (!found) {
count = count + 1
if (count <= 50) {
dp.add(n)
} else if (count == 1000) {
dp1000 = n
} else if (count == 10000) {
dp10000 = n
break
}
}
n = n + 2
}
System.print("First 50 De Polignac numbers:")
Fmt.tprint("$,5d", dp, 10)
Fmt.print("\nOne thousandth: $,d", dp1000)
Fmt.print("\nTen thousandth: $,d", dp10000)
You may also check:How to resolve the algorithm Knapsack problem/Continuous step by step in the D programming language
You may also check:How to resolve the algorithm Five weekends step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Cheryl's birthday step by step in the F# programming language
You may also check:How to resolve the algorithm Haversine formula step by step in the Idris programming language
You may also check:How to resolve the algorithm String comparison step by step in the Oforth programming language