Coprimes: Difference between revisions

m
→‎{{header|REXX}}: simplified the function.
(→‎{{header|Haskell}}: Added a definition and example in Haskell)
m (→‎{{header|REXX}}: simplified the function.)
Line 265:
 
=={{header|REXX}}==
<lang rexx>/*REXX programprgm tests pairsnumber sequences (min. of numberstwo #'s, (separated by a commacommas) to see if they're comprime.*/
parse arg @ /*obtain optional arguments from the CL*/
parse arg @
if @='' | @=="," then @= '21,15 17,23 36,12 18,29 60,15 21,22,25,143 -2,0 0,-3'
 
do j=1 for words(@); say /*process each of the sets of numbers. */
stuff= translate( word(@, j), , ',') /*change all commas (,) to blanks for GCD.*/
cofactor= gcd(stuff) /*get GCD (greatestGreatest Common commonDivisor divisor) of #'s.*/
if cofactor==1 then say stuff " ─────── are coprime ───────"
else say stuff " have a cofactor of: " cofactor
Line 277:
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
gcd: procedure; parse arg $ $= /*╔═══════════════════════════════════════╗╔═══════════════════════════════════╗*/
do #=12 for arg()-1; $= $ arg(#) /*║ This║This GCD can handlehandles multiple arguments║*/
end /*#*/ /*║ and& multiple numbers per argument, and║&║*/
parse var $ x z . /*║ negative║negative numbers and non-integers. ║*/
if x=0 then x= z; x= abs(x) /*╚═══════════════════════════════════════╝╚═══════════════════════════════════╝*/
do j=2 to words($); y= abs( word($, j) ); if y=0 then iterate
do until _==0; _= x // y; x= y; y= _
end /*until*/
end /*j*/