Cubic special primes: Difference between revisions

(Added Sidef)
Line 251:
<pre>
Same as Wren example.
</pre>
 
=={{header|jq}}==
'''Adapted from [[#Julia|Julia]]'''
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
For the definition of `is_prime` used here, see https://rosettacode.org/wiki/Additive_primes<lang jq># Output: an array
def cubic_special_primes:
. as $N
| sqrt as $maxidx
| {cprimes: [2], q: 0}
| until( .cprimes[-1] >= $N or .q >= $N;
label $out
| foreach range(1; $maxidx + 1) as $i (.;
.q = (.cprimes[-1] + ($i * $i * $i))
| if .q > $N
then .emit = true
elif .q | is_prime
then .cprimes = .cprimes + [.q]
| .emit = true
else .
end;
select(.emit)) | {cprimes, q}, break $out )
| .cprimes ;
15000
| ("Cubic special primes < \(.):",
cubic_special_primes)</lang>
{{out}}
<pre>
[2,3,11,19,83,1811,2027,2243,2251,2467,2531,2539,3539,3547,4547,5059,10891,12619,13619,13627,13691,13907,14419]
</pre>
 
2,461

edits