Coprimes: Difference between revisions

1,199 bytes added ,  1 month ago
m
mNo edit summary
 
(4 intermediate revisions by 4 users not shown)
Line 624:
</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#}}==
Line 636 ⟶ 662:
18 and 29 are coprime
</pre>
 
=={{header|Factor}}==
{{works with|Factor|0.98}}
Line 872 ⟶ 899:
<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}}==
Line 1,219 ⟶ 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>
 
Line 1,244 ⟶ 1,300:
{{libheader|Wren-math}}
Two numbers are coprime if their GCD is 1.
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
 
var pairs = [[21,15],[17,23],[36,12],[18,29],[60,15]]
1,969

edits