I have started to reading Structure and Interpretation of Computer Programs since last week. And I finished a few exercise of the first chapter. And this is one of them.

Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.

Following is my solution:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
(define (min x y) (if (< x y) x y))

(define (min3 x y z) (min x (min y z)))

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

(define (sum_of_square x y)
(+ (square x) (square y)))

(define (sum_of_max_two_sqaure x y z)
(define min_num (min3 x y z))
(cond ((= min_num x) (sum_of_square y z))
((= min_num y) (sum_of_square x z))
(else sum_of_square x y)))

(sum_of_max_two_sqaure 1 2 3)