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.
// Defines a procedure that takes three numbers as arguments
// and returns the sum of the squares of the two larger numbers.
// @param a A number
// @param b A number
// @param c A number
// @return The sum of the squares of the two larger numbers
function eq3_1(a, b, c) {
var args = Array.prototype.slice.apply(arguments);
var n = Math.max.apply(null, args);
var m = Math.max.apply.(null, args.splice(args.indexOf(n)), 1);
return n*n + m*m;
}