Cousin primes: Difference between revisions
Content added Content deleted
(Added Sidef) |
|||
Line 1,042: | Line 1,042: | ||
967 971 |
967 971 |
||
Amount: 41</pre> |
Amount: 41</pre> |
||
=={{header|jq}}== |
|||
{{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> |
|||
def cousins: |
|||
# [2,6] is not a cousin so we can start at 3 |
|||
range(3;.;2) |
|||
| select(is_prime and (.+4 | is_prime)) |
|||
| [., .+4]; |
|||
997 | cousins</lang> |
|||
{{out}} |
|||
See below. |
|||
'''The Count''' |
|||
To compute the pairs and the count at the same time without saving them as an array: |
|||
<lang jq>def count(s): reduce s as $x (0; .+1); |
|||
# Use null as the EOS marker |
|||
foreach ((997|cousins),null) as $c (0; .+1; if $c == null then "\nCount is \(.)" else $c end)</lang> |
|||
{{out}} |
|||
<pre> |
|||
[3,7] |
|||
[7,11] |
|||
[13,17] |
|||
[19,23] |
|||
[37,41] |
|||
[43,47] |
|||
[67,71] |
|||
[79,83] |
|||
[97,101] |
|||
[103,107] |
|||
[109,113] |
|||
[127,131] |
|||
[163,167] |
|||
[193,197] |
|||
[223,227] |
|||
[229,233] |
|||
[277,281] |
|||
[307,311] |
|||
[313,317] |
|||
[349,353] |
|||
[379,383] |
|||
[397,401] |
|||
[439,443] |
|||
[457,461] |
|||
[463,467] |
|||
[487,491] |
|||
[499,503] |
|||
[613,617] |
|||
[643,647] |
|||
[673,677] |
|||
[739,743] |
|||
[757,761] |
|||
[769,773] |
|||
[823,827] |
|||
[853,857] |
|||
[859,863] |
|||
[877,881] |
|||
[883,887] |
|||
[907,911] |
|||
[937,941] |
|||
[967,971] |
|||
Count is 42 |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |