Extreme primes: Difference between revisions

Content added Content deleted
(Created page with "<big>Definition</big> <br><br> Write down the first prime number, add the next prime number and if it is prime, add it to the series and so on. These primes are called '''extreme primes''' <br><br> <big>Task</big> <br><br> Find and display the first '''30 p extreme prime''' number on this page. <br><br> =={{header|Ring}}== <syntaxhighlight lang="ring"> see "working..." + nl limit = 2000 Primes = [] for n = 1 to limit if isPrime(n) add(Primes,n) ok next...")
 
(Added Wren (with serious reservations))
Line 48: Line 48:
70241 86453 102001 109147 116533 119069 121631 129419 132059 263171
70241 86453 102001 109147 116533 119069 121631 129419 132059 263171
done...
done...
</pre>

=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
This is very similar to the [[Prime numbers p for which the sum of primes less than or equal to p is prime]] task so I'm highly dubious about converting it to a separate draft task. I also found it at [[oeis:A013918|OEIS-A013918]] though it doesn't appear to have a recognized name.
<syntaxhighlight lang="ecmascript">import "./math" for Int
import "./fmt" for Fmt

var primes = Int.primeSieve(300000)
var extremes = [2]
var sum = 2
var count = 1
for (p in primes.skip(1)) {
sum = sum + p
if (Int.isPrime(sum)) {
extremes.add(sum)
count = count + 1
if (count == 30) break
}
}
System.print("The first 30 extreme primes are:")
Fmt.tprint("$,7d ", extremes, 6)</syntaxhighlight>

{{out}}
<pre>
The first 30 extreme primes are:
2 5 17 41 197 281
7,699 8,893 22,039 24,133 25,237 28,697
32,353 37,561 38,921 43,201 44,683 55,837
61,027 66,463 70,241 86,453 102,001 109,147
116,533 119,069 121,631 129,419 132,059 263,171
</pre>
</pre>