Coprimes: Difference between revisions

1,052 bytes added ,  2 months ago
m
No edit summary
 
(5 intermediate revisions by 5 users not shown)
Line 624:
</pre>
 
 
=={{header|EasyLang}}==
<syntaxhighlight>
func gcd a b .
while b <> 0
h = b
b = a mod b
a = h
end.
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 864 ⟶ 891:
 
function coprimes = coprime(a,b)
coprimesgcds = cell(1,numelgcd(a,b)) == 1;
coprimes{i}(1,:) = a(igcds);
for i = 1:numel(a)
coprimes{i}(2,:) = b(igcds);
if gcd(a(i),b(i)) == 1
coprimes{i}(1) = a(i);
coprimes{i}(2) = b(i);
end
end
not_coprimes = cellfun('isempty',coprimes);
coprimes(not_coprimes) = [];
end</syntaxhighlight>
 
{{out}}
<pre>{[17 23]} 17 {[18 29]}</pre> 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,224 ⟶ 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,249 ⟶ 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]]
2,033

edits