De Polignac numbers: Difference between revisions
Content added Content deleted
(Added Wren) |
|||
Line 146: | Line 146: | ||
Ten thousandth: 273,421</pre> |
Ten thousandth: 273,421</pre> |
||
=={{header|Wren}}== |
|||
{{libheader|Wren-math}} |
|||
{{libheader|Wren-fmt}} |
|||
<syntaxhighlight lang="ecmascript">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)</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
First 50 De Polignac numbers: |
|||
1 127 149 251 331 337 373 509 599 701 |
|||
757 809 877 905 907 959 977 997 1,019 1,087 |
|||
1,199 1,207 1,211 1,243 1,259 1,271 1,477 1,529 1,541 1,549 |
|||
1,589 1,597 1,619 1,649 1,657 1,719 1,759 1,777 1,783 1,807 |
|||
1,829 1,859 1,867 1,927 1,969 1,973 1,985 2,171 2,203 2,213 |
|||
One thousandth: 31,941 |
|||
Ten thousandth: 273,421 |
|||
</pre> |