Next special primes: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: changed the GENP subroutine.)
Line 455: Line 455:
967 1049 82
967 1049 82
</pre>
</pre>

=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''

This entry uses `is_primes` as can be defined as in [[Erd%C5%91s-primes#jq]].
<lang jq>
def primes:
2, (range(3;infinite;2) | select(is_prime));

def emit_until(cond; stream): label $out | stream | if cond then break $out else . end;

def special_primes:
foreach primes as $p ({};
.emit = null
| if .p == null then .p = $p | .emit = .p
else ($p - .p) as $g
| if $g > .gap then .p = $p | .gap=$g | .emit = .p
else .
end
end;
select(.emit).emit);

# The task
# The following assumesg invocation with the -n option:
emit_until(. >= 1050; special_primes)</lang>
{{out}}
Invocation example: jq -n -f program.jq
<pre>
2
3
5
11
19
29
41
59
79
101
127
157
191
227
269
313
359
409
461
521
587
659
733
809
887
967
1049
</pre>



=={{header|Julia}}==
=={{header|Julia}}==