Extreme primes: Difference between revisions

→‎{{header|jq}}: def extremes:
(→‎{{header|jq}}: def extremes:)
Line 245:
 
'''Works with both jq and gojq, the C and Go implementations of jq''' ...
 
Using the generic utilities given immediately below, one solution to the problem
of generating the first 30 extreme primes could be written as follows:
 
<syntaxhighlight lang=jq>
def primes:
2 | recurse(nextprime);
def extremes:
foreach primes as $p (0; . + $p)
| select(is_prime);
 
limit(30; extremes)
</syntaxhighlight>
A program that solves both the primary and stretch tasks is given below.
 
'''Generic Utilities'''
Line 276 ⟶ 291:
| first(range(.+$n; infinite;2) | select(is_prime));
</syntaxhighlight>
'''The TaskTasks'''
<syntaxhighlight lang=jq>
{ extremes:[2],
2,442

edits