Quadrat special primes: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed some comments and whitespace.) |
|||
Line 270: | Line 270: | ||
Same as Wren example. |
Same as Wren example. |
||
</pre> |
</pre> |
||
=={{header|jq}}== |
|||
'''Adaptation of [[#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> |
|||
# Input: a number > 2 |
|||
# Output: an array of the quadrat primes less than `.` |
|||
def quadrat: |
|||
. as $N |
|||
| ($N|sqrt) as $lastn |
|||
| { qprimes: [2], q: 2 } |
|||
| until ( .qprimes[-1] >= $N or .q >= $N; |
|||
label $out |
|||
| foreach range(1; $lastn + 1) as $i (.; |
|||
.q = .qprimes[-1] + $i * $i |
|||
| if .q >= $N then .emit = true |
|||
elif .q|is_prime then .qprimes = .qprimes + [.q] |
|||
| .emit = true |
|||
else . |
|||
end; |
|||
select(.emit)) | {qprimes, q}, break $out ) |
|||
| .qprimes ; |
|||
"Quadrat special primes < 16000:", |
|||
(16000 | quadrat[]) |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
Quadrat special primes < 16000: |
|||
2 |
|||
3 |
|||
7 |
|||
... |
|||
14627 |
|||
14771 |
|||
15671 |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |