From 47a2d186dd9a44a04744f79063fd85b83395746d Mon Sep 17 00:00:00 2001 From: Mad Date: Fri, 13 Sep 2019 22:21:36 +0200 Subject: [PATCH] Project Euler problem 3 in Chicken scheme --- euler3.scm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 euler3.scm diff --git a/euler3.scm b/euler3.scm new file mode 100644 index 0000000..208fec1 --- /dev/null +++ b/euler3.scm @@ -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))) \ No newline at end of file