Extreme primes: Difference between revisions
Content deleted Content added
Converted to a draft task and added a stretch goal (see Wren preamble for rationale). |
→{{header|Wren}}: Changed to deal with stretch goal. |
||
Line 218: | Line 218: | ||
import "./fmt" for Fmt |
import "./fmt" for Fmt |
||
var primes = Int.primeSieve(2000) // say |
|||
var extremes = [2] |
var extremes = [2] |
||
var sum = 2 |
var sum = 2 |
||
var p = 3 |
|||
for (p in primes.skip(1)) { |
|||
var count = 1 |
|||
while (true) { |
|||
sum = sum + p |
sum = sum + p |
||
if (Int.isPrime(sum)) { |
if (Int.isPrime(sum)) { |
||
count = count + 1 |
|||
if ( |
if (count <= 30) { |
||
extremes.add(sum) |
|||
} |
|||
if (count == 30) { |
|||
⚫ | |||
⚫ | |||
System.print() |
|||
} else if (count % 1000 == 0) { |
|||
Fmt.print("The $,d extreme prime is: $,14d for p <= $,9d", count, sum, p) |
|||
if (count == 5000) return |
|||
} |
|||
} |
} |
||
p = Int.nextPrime(p) |
|||
} |
|||
}</syntaxhighlight> |
|||
⚫ | |||
⚫ | |||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
The first 30 extreme primes are: |
The first 30 extreme primes are: |
||
2 5 17 41 197 281 |
2 5 17 41 197 281 |
||
7,699 8,893 22,039 24,133 25,237 28,697 |
7,699 8,893 22,039 24,133 25,237 28,697 |
||
32,353 37,561 38,921 43,201 44,683 55,837 |
32,353 37,561 38,921 43,201 44,683 55,837 |
||
61,027 66,463 70,241 86,453 102,001 109,147 |
61,027 66,463 70,241 86,453 102,001 109,147 |
||
116,533 119,069 121,631 129,419 132,059 263,171 |
116,533 119,069 121,631 129,419 132,059 263,171 |
||
The 1,000 extreme prime is: 1,657,620,079 for p <= 196,831 |
|||
The 2,000 extreme prime is: 9,744,982,591 for p <= 495,571 |
|||
The 3,000 extreme prime is: 24,984,473,177 for p <= 808,837 |
|||
The 4,000 extreme prime is: 49,394,034,691 for p <= 1,152,763 |
|||
The 5,000 extreme prime is: 82,195,983,953 for p <= 1,500,973 |
|||
</pre> |
</pre> |
||