Cousin primes: Difference between revisions
Content added Content deleted
(→{{header|jq}}: correction) |
(→{{header|jq}}: typo) |
||
Line 1,047: | Line 1,047: | ||
'''Works with gojq, the Go implementation of 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> |
For the definition of `is_prime` used here, see https://rosettacode.org/wiki/Additive_primes<lang jq># Output: a stream |
||
def cousins: |
def cousins: |
||
# [2,6] is not a cousin so we can start at 3 |
# [2,6] is not a cousin so we can start at 3 |
||
Line 1,061: | Line 1,061: | ||
To compute the pairs and the count at the same time without saving them as an array:<lang jq># Use null as the EOS marker |
To compute the pairs and the count at the same time without saving them as an array:<lang jq># Use null as the EOS marker |
||
foreach ((997|cousins),null) as $c (1; .+1; if $c == null then "\nCount is \(.)" else $c end)</lang> |
foreach ((997|cousins),null) as $c (-1; .+1; if $c == null then "\nCount is \(.)" else $c end)</lang> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |