Coprimes: Difference between revisions

4,274 bytes added ,  1 month ago
m
(Frink)
 
(9 intermediate revisions by 8 users not shown)
Line 10:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F coprime(a, b)
R gcd(a, b) == 1
 
Line 17:
(36, 12),
(18, 29),
(60, 15)].filter((x, y) -> coprime(x, y)))</langsyntaxhighlight>
 
{{out}}
Line 25:
 
=={{header|8080 Assembly}}==
<langsyntaxhighlight lang="8080asm">puts: equ 9
org 100h
lxi h,pairs
Line 87:
db '***' ; Number output buffer
nbuf: db ' $'
nl: db 13,10,'$'</langsyntaxhighlight>
{{out}}
<pre>17 23
Line 93:
 
=={{header|8086 Assembly}}==
<langsyntaxhighlight lang="asm">puts: equ 9 ; MS-DOS syscall to print a string
cpu 8086
org 100h
Line 143:
db 18,29
db 60,15
dw 0</langsyntaxhighlight>
{{out}}
<pre>17 23
18 29</pre>
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">INT FUNC Gcd(INT a,b)
INT tmp
 
Line 179:
Test(18,29)
Test(60,15)
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Coprimes.png Screenshot from Atari 8-bit computer]
Line 191:
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">BEGIN # test the coprime-ness of some number pairs #
# iterative Greatest Common Divisor routine, returns the gcd of m and n #
PROC gcd = ( INT m, n )INT:
Line 214:
FI
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 223:
=={{header|ALGOL W}}==
{{Trans|MAD}}
<langsyntaxhighlight lang="algolw">BEGIN % check whether sme numbers are coPrime (their gcd is 1) or not %
LOGICAL PROCEDURE COPRM ( INTEGER VALUE X, Y ) ; GCD( X, Y ) = 1;
INTEGER PROCEDURE GCD ( INTEGER VALUE A, B ) ;
Line 247:
IF COPRM( PP, QQ ) THEN WRITE( I_W := 4, S_W := 0, PP, QQ )
END FOR_I
END.</langsyntaxhighlight>
{{out}}
<pre>
Line 257:
=={{header|APL}}==
{{works with|Dyalog APL}}
<langsyntaxhighlight lang="apl">(⊢(/⍨)1=∨/¨) (21 15)(17 23)(36 12)(18 29)(60 15)</langsyntaxhighlight>
{{out}}
<pre>┌─────┬─────┐
Line 264:
 
=={{header|AppleScript}}==
<langsyntaxhighlight lang="applescript">on hcf(a, b)
repeat until (b = 0)
set x to a
Line 282:
if (hcf(p, q) is 1) then set end of coprimes to thisPair's contents
end repeat
return coprimes</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">{{17, 23}, {18, 29}}</langsyntaxhighlight>
 
 
or, composing a definition and test from more general functions:
<langsyntaxhighlight lang="applescript">------------------------- COPRIME ------------------------
 
-- coprime :: Int -> Int -> Bool
Line 365:
end script
end if
end mReturn</langsyntaxhighlight>
{{Out}}
<pre>{{17, 23}, {18, 29}}</pre>
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">coprimes?: function [a b] -> 1 = gcd @[a b]
 
loop [[21 15] [17 23] [36 12] [18 29] [60 15]] 'pair [
print [pair\0 "and" pair\1 "ara" (coprimes? pair\0 pair\1)? -> "coprimes." -> "not coprimes."]
]</langsyntaxhighlight>
 
{{out}}
Line 385:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f COPRIMES.AWK
BEGIN {
Line 402:
return(q?gcd(q,(p%q)):p)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 410:
 
=={{header|BASIC}}==
<langsyntaxhighlight lang="basic">10 DEFINT A-Z
20 READ N
30 FOR I=1 TO N
Line 424:
130 DATA 36,12
140 DATA 18,29
150 DATA 60,15</langsyntaxhighlight>
{{out}}
<pre> 17 23
Line 430:
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
let gcd(a,b) = b=0 -> a, gcd(b, a rem b)
Line 442:
for i=0 to n-1
if coprime(ps!i, qs!i) do writef("%N %N*N", ps!i, qs!i)
$)</langsyntaxhighlight>
{{out}}
<pre>17 23
Line 448:
 
=={{header|BQN}}==
<langsyntaxhighlight lang="bqn">GCD ← {𝕨(|𝕊⍟(>⟜0)⊣)𝕩}
SelectCoprimes ← (1=GCD´¨)⊸/
 
SelectCoprimes ⟨21‿15,17‿23,36‿12,18‿29,60‿15⟩</langsyntaxhighlight>
{{out}}
<pre>⟨ ⟨ 17 23 ⟩ ⟨ 18 29 ⟩ ⟩</pre>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
 
int gcd(int a, int b) {
Line 487:
}
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>{17, 23}
Line 493:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <algorithm>
#include <vector>
Line 532:
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>{17, 23}
Line 538:
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub gcd(a: uint8, b: uint8): (r: uint8) is
Line 571:
end if;
i := i + 1;
end loop;</langsyntaxhighlight>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
 
function GreatestCommonDivisor(A,B: integer): integer;
begin
if B = 0 then Result:=A
else Result:=GreatestCommonDivisor( B, A mod B);
end;
 
 
function IsCoprime(A,B: integer): boolean;
begin
Result:=GreatestCommonDivisor(A,B)=1;
end;
 
 
const TestNumbers: array [0..4] of TPoint =
((X:21;Y:15),(X:17;Y:23),(X:36;Y:12),(X:18;Y:29),(X:60;Y:15));
 
 
procedure ShowCoprimes(Memo: TMemo);
var I: integer;
var S: string;
var TN: TPoint;
begin
for I:=0 to High(TestNumbers) do
begin
TN:=TestNumbers[I];
S:=IntToStr(TN.X)+' '+IntToStr(TN.Y)+' is ';
if IsCoprime(TN.X,TN.Y) then S:=S+'coprime'
else S:=S+'not coprime';
Memo.Lines.Add(S);
end;
end;
 
</syntaxhighlight>
{{out}}
<pre>
21 15 is not coprime
17 23 is coprime
36 12 is not coprime
18 29 is coprime
60 15 is not coprime
Elapsed Time: 5.729 ms.
</pre>
 
 
=={{header|EasyLang}}==
<syntaxhighlight>
func gcd a b .
while b <> 0
h = b
b = a mod b
a = h
.
return a
.
proc test p[] . .
if gcd p[1] p[2] = 1
print p[]
.
.
pairs[][] = [ [ 21 15 ] [ 17 23 ] [ 36 12 ] [ 18 29 ] [ 60 15 ] ]
for i to len pairs[][]
test pairs[i][]
.
</syntaxhighlight>
{{out}}
<pre>
[ 17 23 ]
[ 18 29 ]
</pre>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// Coprimes. Nigel Galloway: May 4th., 2021
let rec fN g=function 0->g=1 |n->fN n (g%n)
[(21,15);(17,23);(36,12);(18,29);(60,15)] |> List.filter(fun(n,g)->fN n g)|>List.iter(fun(n,g)->printfn "%d and %d are coprime" n g)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 584 ⟶ 662:
18 and 29 are coprime
</pre>
 
=={{header|Factor}}==
{{works with|Factor|0.98}}
<langsyntaxhighlight lang="factor">USING: io kernel math prettyprint sequences ;
 
: coprime? ( seq -- ? ) [ ] [ simple-gcd ] map-reduce 1 = ;
Line 598 ⟶ 677:
{ 21 22 25 31 143 }
}
[ dup pprint coprime? [ " Coprime" write ] when nl ] each</langsyntaxhighlight>
{{out}}
<pre>
Line 610 ⟶ 689:
 
=={{header|Fermat}}==
<langsyntaxhighlight lang="fermat">Func Is_coprime(a, b) = if GCD(a,b)=1 then 1 else 0 fi.</langsyntaxhighlight>
 
=={{header|FOCAL}}==
<langsyntaxhighlight lang="focal">01.10 S P(1)=21; S Q(1)=15
01.20 S P(2)=17; S Q(2)=23
01.30 S P(3)=36; S Q(3)=12
Line 633 ⟶ 712:
03.40 I (A-1)3.6,3.5,3.6
03.50 T %4,P(N),Q(N),!
03.60 R</langsyntaxhighlight>
{{out}}
<pre>= 17= 23
Line 639 ⟶ 718:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">function gcdp( a as uinteger, b as uinteger ) as uinteger
'returns the gcd of two positive integers
if b = 0 then return a
Line 659 ⟶ 738:
print is_coprime(18,29)
print is_coprime(60,15)
</syntaxhighlight>
</lang>
{{out}}<pre>
false
Line 669 ⟶ 748:
 
=={{header|Frink}}==
<langsyntaxhighlight lang="frink">pairs = [ [21,15],[17,23],[36,12],[18,29],[60,15] ]
for [a,b] = pairs
println["[$a, $b] are " + (gcd[a,b] == 1 ? "" : "not ") + "coprime"]</langsyntaxhighlight>
{{out}}
<pre>
Line 684 ⟶ 763:
{{libheader|Go-rcu}}
Uses the same observation as the Wren entry.
<langsyntaxhighlight lang="go">package main
 
import (
Line 699 ⟶ 778:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 709 ⟶ 788:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">------------------------- COPRIMES -----------------------
 
coprime :: Integral a => a -> a -> Bool
Line 726 ⟶ 805:
(18, 29),
(60, 15)
]</langsyntaxhighlight>
{{Out}}
<pre>[(17,23),(18,29)]</pre>
Line 732 ⟶ 811:
 
=={{header|J}}==
<langsyntaxhighlight Jlang="j">([#~1=+./"1) >21 15;17 23;36 12;18 29;60 15</langsyntaxhighlight>
{{out}}
<pre>17 23
Line 740 ⟶ 819:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<syntaxhighlight lang="jq">
<lang jq>
# Note that jq optimizes the recursive call of _gcd in the following:
def gcd(a;b):
Line 749 ⟶ 828:
# Input: an array
def coprime: gcd(.[0]; .[1]) == 1;
</syntaxhighlight>
</lang>
'''The task'''
<langsyntaxhighlight lang="jq">"The following pairs of numbers are coprime:",
([[21,15],[17,23],[36,12],[18,29],[60,15]][]
| select(coprime))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 763 ⟶ 842:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">filter(p -> gcd(p...) == 1, [[21,15],[17,23],[36,12],[18,29],[60,15],[21,22,25,31,143]])
</langsyntaxhighlight>{{out}}<pre>
3-element Vector{Vector{Int64}}:
[17, 23]
Line 772 ⟶ 851:
 
=={{header|MAD}}==
<langsyntaxhighlight MADlang="mad"> NORMAL MODE IS INTEGER
INTERNAL FUNCTION COPRM.(X,Y) = GCD.(X,Y).E.1
Line 797 ⟶ 876:
VECTOR VALUES FMT = $I4,I4*$
END OF PROGRAM </langsyntaxhighlight>
{{out}}
<pre>COPRIMES
Line 804 ⟶ 883:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">CoprimeQ @@@ {{21, 15}, {17, 23}, {36, 12}, {18, 29}, {60, 15}}</langsyntaxhighlight>
{{out}}
<pre>{False, True, False, True, False}</pre>
 
=={{header|MATLAB}}==
<syntaxhighlight lang="matlab">disp(coprime([21, 17, 36, 18, 60], [15, 23, 12, 29, 15]));
 
function coprimes = coprime(a,b)
gcds = gcd(a,b) == 1;
coprimes(1,:) = a(gcds);
coprimes(2,:) = b(gcds);
end</syntaxhighlight>
 
{{out}}
<pre> 17 18
23 29</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
/* Taken the list of pairs and making a sublist of those pairs that are coprimes */
pairs:[[21,15],[17,23],[36,12],[18,29],[60,15]]$
sublist(pairs,lambda([x],apply('gcd,x)=1));
</syntaxhighlight>
{{out}}
<pre>
[[17,23],[18,29]]
</pre>
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import math
 
for (a, b) in [(21, 15), (17, 23), (36, 12), (18, 29), (60, 15)]:
echo a, " and ", b, " are ", if gcd(a, b) == 1: "coprimes." else: "not coprimes."</langsyntaxhighlight>
 
{{out}}
Line 820 ⟶ 923:
18 and 29 are coprimes.
60 and 15 are not coprimes.</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let rec is_coprime a = function
| 0 -> a = 1
| b -> is_coprime b (a mod b)
 
let () =
let p (a, b) =
Printf.printf "%u and %u are%s coprime\n" a b (if is_coprime a b then "" else " not")
in
List.iter p [21, 15; 17, 23; 36, 12; 18, 29; 60, 15]</syntaxhighlight>
{{out}}
<pre>
21 and 15 are not coprime
17 and 23 are coprime
36 and 12 are not coprime
18 and 29 are coprime
60 and 15 are not coprime
</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use ntheory 'gcd';
Line 829 ⟶ 951:
printf "%7s %s\n", (gcd(@$_) == 1 ? 'Coprime' : ''), join ', ', @$_
for [21,15], [17,23], [36,12], [18,29], [60,15], [21,22,25,31,143];
</syntaxhighlight>
</lang>
{{out}}
<pre> 21, 15
Line 839 ⟶ 961:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">function</span> <span style="color: #000000;">gcd1</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">gcd</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">1</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">({{</span><span style="color: #000000;">21</span><span style="color: #0000FF;">,</span><span style="color: #000000;">15</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">17</span><span style="color: #0000FF;">,</span><span style="color: #000000;">23</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">36</span><span style="color: #0000FF;">,</span><span style="color: #000000;">12</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">18</span><span style="color: #0000FF;">,</span><span style="color: #000000;">29</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">60</span><span style="color: #0000FF;">,</span><span style="color: #000000;">15</span><span style="color: #0000FF;">}},</span><span style="color: #000000;">gcd1</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 848 ⟶ 970:
</pre>
A longer set/element such as {21,22,25,30,143} would also be shown as coprime, since it is, albeit not pairwise coprime - for the latter you would need something like:
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #008080;">function</span> <span style="color: #000000;">pairwise_coprime</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span>
Line 858 ⟶ 980:
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">({{</span><span style="color: #000000;">21</span><span style="color: #0000FF;">,</span><span style="color: #000000;">15</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">17</span><span style="color: #0000FF;">,</span><span style="color: #000000;">23</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">36</span><span style="color: #0000FF;">,</span><span style="color: #000000;">12</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">18</span><span style="color: #0000FF;">,</span><span style="color: #000000;">29</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">60</span><span style="color: #0000FF;">,</span><span style="color: #000000;">15</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">21</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">22</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">25</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">31</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">143</span><span style="color: #0000FF;">}},</span><span style="color: #000000;">pairwise_coprime</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
Output is the same as the above, because this excludes the {21, 22, 25, 31, 143}, since both 22 and 143 are divisible by 11.
 
=={{header|PL/M}}==
<langsyntaxhighlight lang="plm">100H:
BDOS: PROCEDURE (FN, ARG);
DECLARE FN BYTE, ARG ADDRESS;
Line 911 ⟶ 1,033:
END;
CALL BDOS(0,0);
EOF</langsyntaxhighlight>
{{out}}
<pre>17 23
Line 917 ⟶ 1,039:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">'''Coprimes'''
 
from math import gcd
Line 945 ⟶ 1,067:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>[(17, 23), (18, 29)]</pre>
Line 954 ⟶ 1,076:
<code>gcd</code> is defined at [[Greatest common divisor#Quackery]].
 
<langsyntaxhighlight Quackerylang="quackery"> [ gcd 1 = ] is coprime ( n n --> b )
 
' [ [ 21 15 ]
Line 968 ⟶ 1,090:
coprime not if
[ say " not" ]
say " coprime." cr ]</langsyntaxhighlight>
 
{{out}}
Line 980 ⟶ 1,102:
 
=={{header|R}}==
<langsyntaxhighlight lang="rsplus">factors <- function(n) c(Filter(function(x) n %% x == 0, seq_len(n %/% 2)), n)
isCoprime <- function(p, q) all(intersect(factors(p), factors(q)) == 1)
output <- data.frame(p = c(21, 17, 36, 18, 60), q = c(15, 23, 12, 29, 15))
print(transform(output, "Coprime" = ifelse(mapply(isCoprime, p, q), "Yes", "No")))</langsyntaxhighlight>
{{out}}
<pre> p q Coprime
Line 996 ⟶ 1,118:
There is a coprime? function in the math/number-theory library to show off (more useful if you're using typed racket).
 
<langsyntaxhighlight lang="racket">#lang racket/base
 
;; Rename only necessary so we can distinguish it
Line 1,015 ⟶ 1,137:
(list number-theory/coprime?
gcd/coprime?
(λ ns (= 1 (apply gcd ns))))))</langsyntaxhighlight>
 
{{out}}
Line 1,044 ⟶ 1,166:
How do you determine if numbers are co-prime? Check to see if the [[Greatest common divisor]] is equal to one. Since we're duplicating tasks willy-nilly, lift code from [[Greatest_common_divisor#Raku|that task]], (or in this case, just use the builtin).
 
<syntaxhighlight lang="raku" perl6line>say .raku, ( [gcd] |$_ ) == 1 ?? ' Coprime' !! '' for [21,15],[17,23],[36,12],[18,29],[60,15],[21,22,25,31,143]</langsyntaxhighlight>
<pre>[21, 15]
[17, 23] Coprime
Line 1,053 ⟶ 1,175:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX prgm tests number sequences (min. of two #'s, separated by a commas) if comprime.*/
parse arg @ /*obtain optional arguments from the CL*/
if @='' | @=="," then @= '21,15 17,23 36,12 18,29 60,15 21,22,25,143 -2,0 0,-3'
Line 1,074 ⟶ 1,196:
end /*until*/
end /*j*/
return x</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 1,095 ⟶ 1,217:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
see "working..." + nl
row = 0
Line 1,125 ⟶ 1,247:
see "Found " + row + " coprimes" + nl
see "done..." + nl
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,135 ⟶ 1,257:
Found 2 coprimes
done...
</pre>
 
=={{header|RPL}}==
<code>GCD</code> is defined at [[Greatest common divisor#RPL|Greatest common divisor]]
{{works with|HP|28}}
≪ → pairs
≪ { }
1 pairs SIZE '''FOR''' j
pairs j GET
DUP LIST→ DROP
'''IF''' <span style="color:blue">GCD</span> 1 == '''THEN''' 1 →LIST + '''ELSE''' DROP '''END'''
'''NEXT'''
≫ '<span style="color:blue">→COPR</span>' STO
 
{{21 15} {17 23} {36 12} {18 29} {60 15}} <span style="color:blue">→COPR</span>
{{out}}
<pre>
1: { { 17 23 } { 18 29 } }
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">pairs = [[21,15],[17,23],[36,12],[18,29],[60,15]]
pairs.select{|p, q| p.gcd(q) == 1}.each{|pair| p pair}
</syntaxhighlight>
</lang>
{{out}}
<pre>[17, 23]
Line 1,147 ⟶ 1,287:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">var pairs = [[21,15],[17,23],[36,12],[18,29],[60,15]]
say "The following pairs of numbers are coprime:"
pairs.grep { .gcd == 1 }.each { .say }</langsyntaxhighlight>
{{out}}
<pre>
Line 1,160 ⟶ 1,300:
{{libheader|Wren-math}}
Two numbers are coprime if their GCD is 1.
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int
 
var pairs = [[21,15],[17,23],[36,12],[18,29],[60,15]]
System.print("The following pairs of numbers are coprime:")
for (pair in pairs) if (Int.gcd(pair[0], pair[1]) == 1) System.print(pair)</langsyntaxhighlight>
 
{{out}}
Line 1,174 ⟶ 1,314:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">func GCD(A, B); \Return greatest common divisor of A and B
int A, B;
[while A#B do
Line 1,189 ⟶ 1,329:
[IntOut(0, A); ChOut(0, ^,); IntOut(0, B); CrLf(0)];
];
]</langsyntaxhighlight>
 
{{out}}
1,969

edits