Project Euler Problem 6 in Chicken Scheme
This commit is contained in:
parent
47a2d186dd
commit
c6d44965da
1 changed files with 15 additions and 0 deletions
15
euler6.scm
Normal file
15
euler6.scm
Normal 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))
|
Loading…
Reference in a new issue