Prime numbers p for which the sum of primes less than or equal to p is prime: Difference between revisions

Line 244:
{{out}}
<pre>2 3 7 13 37 43 281 311 503 541 557 593 619 673 683 733 743 839 881 929 953</pre>
 
=={{header|jq}}==
'''Adapted from [[#Wren|Wren]]'''
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
See [[Erdős-primes#jq]] for a suitable definition of `is_prime` as
used here.
 
<lang jq>def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
 
# Output: a stream of primes in range(0;$n)
def primes($n):
2, (range(3;$n;2) | select(is_prime));
 
# Output: a stream of primes satisfying the condition
def results($n):
[primes($n)] as $primes
| ($primes | add) as $maxSum
| [range(0; $maxSum) | is_prime] as $c
| foreach $primes[] as $p (0;
. + $p;
select($c[.]) | $p );
 
def task($n):
"Primes 'p' under \($n) for which the sum of primes <= p is also prime:",
( [results($n)]
| (_nwise(7) | map(lpad(4)) | join(" ")),
"\nFound \(length) such primes." );
 
task(1000)</lang>
{{out}}
<pre>
Primes 'p' under 1000 for which the sum of primes <= p is also prime:
2 3 7 13 37 43 281
311 503 541 557 593 619 673
683 733 743 839 881 929 953
 
Found 21 such primes.
</pre>
 
=={{header|Julia}}==
2,442

edits