Extreme primes: Difference between revisions

Added Easylang
(Added Sidef)
(Added Easylang)
 
(3 intermediate revisions by 3 users not shown)
Line 130:
<pre>
Identical to Wren output.
</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
fastfunc isprim num .
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
prim = 2
proc nextprim . .
repeat
prim += 1
until isprim prim = 1
.
.
while cnt < 30
n += prim
if isprim n = 1
cnt += 1
write n & " "
.
nextprim
.
</syntaxhighlight>
{{out}}
<pre>
2 5 17 41 197 281 7699 8893 22039 24133 25237 28697 32353 37561 38921 43201 44683 55837 61027 66463 70241 86453 102001 109147 116533 119069 121631 129419 132059 263171
</pre>
 
Line 641 ⟶ 674:
</pre>
 
=={{header|RPL}}==
{{works with|HP|49}}
« 0 → max sum
« { } 1
'''DO'''
NEXTPRIME
DUP 'sum' STO+
'''IF''' sum ISPRIME? '''THEN''' SWAP sum + SWAP '''END'''
'''UNTIL''' OVER SIZE max ≥ '''END'''
DROP2
» » ‘<span style="color:blue">XPRIM</span>’ STO
30 <span style="color:blue">XPRIM</span>
{{out}}
<pre>
1: { 2 5 17 41 197 281 7699 8893 22039 24133 25237 28697 32353 37561 38921 43201 44683 55837 61027 66463 70241 86453 102001 109147 116533 119069 121631 129419 132059 263171 }
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">require 'prime'
 
sum, n = 0, 30
extreme_primes = Prime.lazy.filter_map{|pr|sum += pr; [pr, sum] if sum.prime?}
 
puts "The first #{n} extreme primes are:"
extreme_primes.first(30).map(&:last).each_slice(10){|slice| puts "%8d"*slice.size % slice}
 
sum = 0
puts
extreme_primes.first(5000).each_slice(1000).with_index(1) do|slice, i|
puts "The %dth extreme prime is sum of primes upto %10d: %12d" % [i*1000, *slice.last]
end
</syntaxhighlight>
{{out}}
<pre>The first 30 extreme primes are:
2 5 17 41 197 281 7699 8893 22039 24133
25237 28697 32353 37561 38921 43201 44683 55837 61027 66463
70241 86453 102001 109147 116533 119069 121631 129419 132059 263171
 
The 1000th extreme prime is sum of primes upto 196831: 1657620079
The 2000th extreme prime is sum of primes upto 495571: 9744982591
The 3000th extreme prime is sum of primes upto 808837: 24984473177
The 4000th extreme prime is sum of primes upto 1152763: 49394034691
The 5000th extreme prime is sum of primes upto 1500973: 82195983953
</pre>
=={{header|Sidef}}==
{{trans|Julia}}
Line 702 ⟶ 779:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./fmt" for Fmt
 
Line 746 ⟶ 823:
===Embedded (GMP)===
{{libheader|Wren-gmp}}
<syntaxhighlight lang="ecmascriptwren">import "./gmp" for Mpz
import "./fmt" for Fmt
 
1,983

edits