Project Euler Problem 6 in Chicken Scheme

This commit is contained in:
madmaurice 2019-09-13 22:40:06 +02:00
parent 47a2d186dd
commit c6d44965da

15
euler6.scm Normal file
View file

@ -0,0 +1,15 @@
(define (range a b)
(if (> a b) '() (cons a (range (add1 a) b))))
(define (sum lst)
(foldl + 0 lst))
(define (sqr a)
(* a a))
(define (problem6 v)
(let ((r (range 1 v)))
(- (sqr (sum r)) (sum (map sqr r)))))
(print (problem6 10))
(print (problem6 100))