Prime numbers p for which the sum of primes less than or equal to p is prime: Difference between revisions
Content added Content deleted
m (Peak moved page Prime numbers p which sum of prime numbers less or equal to p is prime to Prime numbers p for which the sum of primes less than or equal to p is prime: grammar and comprehensibility) |
|||
Line 244: | Line 244: | ||
{{out}} |
{{out}} |
||
<pre>2 3 7 13 37 43 281 311 503 541 557 593 619 673 683 733 743 839 881 929 953</pre> |
<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}}== |
=={{header|Julia}}== |