Anonymous user
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
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'
do j=1 for words(@); say /*process
stuff= translate( word(@, j), , ',') /*change
cofactor= gcd(stuff) /*get
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 #=
end /*#*/ /*║
parse var $ x z . /*
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*/
|