|
SketchyLISP Reference |
Copyright (C) 2007 Nils M Holm |
| <<[last] | [Index] | [length]>> |
Conformance: R5RS Scheme
Purpose: Compute the least common multiple of a sequence of numbers.
Arguments:
A... - numbers
Implementation:
(define (lcm . a)
(letrec
((_lcm
(lambda (a b)
(let ((cd (gcd a b)))
(n* cd (n* (nquotient a cd)
(nquotient b cd)))))))
(fold-left _lcm 1 (map (lambda (x)
(natural (abs x)))
a))))
Example:
(lcm 32 -36) => 288
| <<[last] | [Index] | [length]>> |