Project Euler problem 3 in Chicken scheme

This commit is contained in:
madmaurice 2019-09-13 22:21:36 +02:00
parent 56c5970395
commit 47a2d186dd

16
euler3.scm Normal file
View file

@ -0,0 +1,16 @@
(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)))