Solution to SICP Exercise 1.3

Structure and Interpretation of Computer Programs

Solution to Exercise 1.3:

(define (square x)
(* x x))

(define (sum-of-squares x y)
(+ (square x) (square y)))

(define (sum-of-squares-of-two-larger x y z)
(cond ((and (<= x y) (<= x z)) (sum-of-squares y z))
((and (<= y x) (<= y z)) (sum-of-squares x z))
(else (sum-of-squares x y))))

Advertisements