Project Euler problem 3 in Chicken scheme
This commit is contained in:
parent
56c5970395
commit
47a2d186dd
1 changed files with 16 additions and 0 deletions
16
euler3.scm
Normal file
16
euler3.scm
Normal 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)))
|
Loading…
Reference in a new issue