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

Content added Content deleted
(→‎{{header|jq}}: simplify)
Line 246: Line 246:


=={{header|jq}}==
=={{header|jq}}==
'''Adapted from [[#Wren|Wren]]'''
{{works with|jq}}
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
'''Works with gojq, the Go implementation of jq'''

This entry adopts the straightforward approach as used for example in the [[#awk|awk]] entry.
The jq implementation of this approach also turns out to be significantly faster than the jq implementation of the approach used in the [[#Wren|Wren]] entry.


See [[Erdős-primes#jq]] for a suitable definition of `is_prime` as
See [[Erdős-primes#jq]] for a suitable definition of `is_prime` as
Line 261: Line 263:
# Output: a stream of primes satisfying the condition
# Output: a stream of primes satisfying the condition
def results($n):
def results($n):
[primes($n)] as $primes
foreach primes($n) as $p (0;
| ($primes | add) as $maxSum
. + $p;
| [range(0; $maxSum) | is_prime] as $c
select(is_prime) | $p );
| foreach $primes[] as $p (0;
. + $p;
select($c[.]) | $p );


def task($n):
def task($n):