Coprimes: Difference between revisions

(Added Sidef)
Line 637:
<pre>17 23
18 29</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<lang jq>
# Note that jq optimizes the recursive call of _gcd in the following:
def gcd(a;b):
def _gcd:
if .[1] != 0 then [.[1], .[0] % .[1]] | _gcd else .[0] end;
[a,b] | _gcd ;
 
# Input: an array
def coprime: gcd(.[0]; .[1]) == 1;
</lang>
'''The task'''
<lang jq>"The following pairs of numbers are coprime:",
([[21,15],[17,23],[36,12],[18,29],[60,15]][]
| select(coprime))
</lang>
{{out}}
<pre>
The following pairs of numbers are coprime:
[17,23]
[18,29]
</pre>
 
=={{header|Julia}}==
2,442

edits