Coprimes: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added pairwise coprimes version) |
m (→{{header|Python}}: Added a solution using Python) |
||
Line 196: | Line 196: | ||
<!--</lang>--> |
<!--</lang>--> |
||
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. |
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|Python}}== |
|||
<lang python>'''Coprimes''' |
|||
from math import gcd |
|||
# coprime :: Int -> Int -> Bool |
|||
def coprime(a, b): |
|||
'''True if a and b are coprime. |
|||
''' |
|||
return 1 == gcd(a, b) |
|||
# ------------------------- TEST ------------------------- |
|||
# main :: IO () |
|||
def main(): |
|||
'''List of pairs filtered for coprimes''' |
|||
print([ |
|||
xy for xy in [ |
|||
(21, 15), (17, 23), (36, 12), |
|||
(18, 29), (60, 15) |
|||
] |
|||
if coprime(*xy) |
|||
]) |
|||
# MAIN --- |
|||
if __name__ == '__main__': |
|||
main()</lang> |
|||
{{Out}} |
|||
<pre>[(17, 23), (18, 29)]</pre> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |