23 lines
478 B
Scheme
23 lines
478 B
Scheme
(define (gcd x y)
|
|
(if (= y 0) x
|
|
(gcd y (modulo x y))))
|
|
|
|
(define (lcm x y)
|
|
(/ (* x y) (gcd x y)))
|
|
|
|
(define (lcmlis lis)
|
|
(define (lcm-iter lis a)
|
|
(if (= (length lis) 1) (lcm (car lis) a)
|
|
(lcm-iter (cdr lis) (lcm a (car lis)))))
|
|
(lcm-iter (cdr lis) (car lis)))
|
|
|
|
(define (makelis x)
|
|
(define (makelis-iter x lis)
|
|
(if (zero? x) lis
|
|
(makelis-iter (- x 1) (append (list x) lis))))
|
|
(makelis-iter x '()))
|
|
|
|
|
|
(display (lcmlis (makelis 100)))
|
|
(newline)
|