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: Haxus the Novice 2009-09-05 5:55

Fuck, I came up with this after reading the first sections of SICP (leading up to the exercise obviously):

(define (sum-of-high-two-sq a b c)
  (cond ((< a b) (if (< a c)
                             (+ (square b) (square c))
                             (+ (square a) (square b))
                 ))
        (else (if (> b c)
                          (+ (square a) (square b))
                          (+ (square a) (square c))))))


As I look through the code posted in this thread I realize I still have far to go to become an EXPERT PROGRAMMER

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