RosettaCodeData/Task/Least-common-multiple/Forth/least-common-multiple.fth

7 lines
142 B
Forth
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
: gcd ( a b -- n )
begin dup while tuck mod repeat drop ;
: lcm ( a b -- n )
over 0= over 0= or if 2drop 0 exit then
2dup gcd abs */ ;