Extreme primes: Difference between revisions
Content added Content deleted
(add RPL) |
(→{{header|Ruby}}: Add Ruby) |
||
Line 658: | Line 658: | ||
</pre> |
</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}}== |
=={{header|Sidef}}== |
||
{{trans|Julia}} |
{{trans|Julia}} |