one-file-projects/euler3.scm

16 lines
No EOL
381 B
Scheme

(define (factors n)
(let loop ((val n) (div 2) (factors '()))
(if (= 1 val)
factors
(if (= 0 (modulo val div))
(loop (/ val div) div (cons div factors))
(loop val (add1 div) factors)
)
)
)
)
(define (max lst)
(foldl (lambda (a b) (if (> a b) a b)) (car lst) (cdr lst)))
(print (max (factors 600851475143)))