mirror of
https://git.sr.ht/~crc_/retroforth
synced 2024-11-16 19:48:56 +01:00
28260d7709
FossilOrigin-Name: 154e68f1885daf32f0749ba8778cf4efe3d650bfeee6439b1ef298f8c64f33f0
19 lines
418 B
Text
19 lines
418 B
Text
# Least Common Multiple
|
|
|
|
The least common multiple of two integers a and b, is the
|
|
smallest positive integer that is divisible by both a and b.
|
|
|
|
This implements a word to find this in RETRO.
|
|
|
|
It uses a formula that reduces the problem to computing the
|
|
greatest common divisor (gcd), as in:
|
|
|
|
lcm(a,b) = |a*b| / gcd(a,b)
|
|
|
|
~~~
|
|
:gcd (ab-n)
|
|
[ tuck mod dup ] while drop ;
|
|
|
|
:lcm (ab-n)
|
|
dup-pair gcd [ * ] dip / ;
|
|
~~~
|