Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

SICP Exercise 1.3

Name: Anonymous 2008-01-19 7:59

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

(define (ex3 x y z)
                     (cond
                       ((> y z x) ((define a x) (define b y) (+ (square a) (square b))))
                       ((> y x z) ((define a x) (define b y) (+ (square a) (square b))))
                       ((> z y x) ((define a x) (define b y) (+ (square a) (square b))))
                       ((> z x y) ((define a x) (define b y) (+ (square a) (square b))))
                       ((> x z y) ((define a x) (define b y) (+ (square a) (square b))))
                       ((> x y z) ((define a x) (define b y) (+ (square a) (square b)))))


I know I'm thinking about this the wrong way. My solution doesn't work.

Name: Anonymous 2008-01-19 13:44

I don't know LISP, but if i wanted to break it down functionally, i'd break it down this way:

First have a function that takes the three numbers and returns the two largest.

Second, have a function that squares two numbers, adds them and returns the result.

The argument of the second function is the result of the of the first function etc.





The design of the first function should be trivial. Finding the two largest numbers is the hard part of the problem.

I'm too drunk too push around the variables right now so I'll lets some other adequately quallified computer scientist fag do it

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List