Source

snippets / euler / 006-squareofsums.scm

Full commit
; project euler problem 6
; find the difference between the sum of squares and the square of the sums of
; all integers from 1 to 100

(define (sum f a b)
	(if (> a b) 0
		(+ (f a) (sum f (+ a 1) b))))
(define (ident x) x) 
(define (square x) (* x x))
(define (abs x) (if (< x 0) (- x) x))
(define (difference x, y) (abs (- x y)))
(define (sum-of-squares a b) (sum square a b))
(define (square-of-sums a b) (square (sum ident a b)))

(display (difference (sum-of-squares 1 100) (square-of-sums 1 100)))
(newline)