From: ······@my-deja.com
Subject: Simple program question
Date: 
Message-ID: <860nlt$cs4$1@nnrp1.deja.com>
Hello everyone,

How can I define a procedure that takes three numbers as arguments and
returns the sum of the squares of the two larger numbers ?

Thanks a lot

--
Yours truly,
Pat


Sent via Deja.com http://www.deja.com/
Before you buy.

From: Tony
Subject: Re: Simple program question
Date: 
Message-ID: <15d84bec.4ac11222@usw-ex0110-076.remarq.com>
There are several ways to do this, the easyest being...

(defun sum_sq (a b c)
    (let ((temp (sort (list a b c) #'>)))
       (+ (square (car temp))(square (cadr temp)))))

That should do it



* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful
From: Tim Bradshaw
Subject: Re: Simple program question
Date: 
Message-ID: <ey3hfgb8xeh.fsf@cley.com>
* patcyr  wrote:
> Hello everyone,
> How can I define a procedure that takes three numbers as arguments and
> returns the sum of the squares of the two larger numbers ?


int sum_of_two_largest(int x, y, z)
{
    int l1; l2;
    if (x >= y) {
	l1 = x;
	l2 = (y >= z) ? y : z;
    } else {
	l1 = y;
	l2 = (x >= z) ? x : z;
    }

    return l1 *l1 + l2 * l2;
	    
}
From: Stig Hemmer
Subject: Re: Simple program question
Date: 
Message-ID: <ekvg0vv5uxr.fsf@gnoll.pvv.ntnu.no>
······@my-deja.com writes:
> How can I define a procedure that takes three numbers as arguments and
> returns the sum of the squares of the two larger numbers ?

(defun
the-sum-of-the-squares-of-the-two-largest-numbers-in-a-set-of-three
(first-number second-number third-number) (+ (/ (+ (* (- first-number
second-number)(- first-number second-number)) (* (+ first-number
second-number)(+ first-number second-number)) ) 2) (* (+ third-number
(min first-number second-number third-number))(- third-number (min
first-number second-number third-number)))))

Stig Hemmer,
Jack of a Few Trades.
From: Arne Knut Roev
Subject: Re: Simple program question
Date: 
Message-ID: <FoJouy.4oE@online.no>
······@my-deja.com wrote:
> How can I define a procedure that takes three numbers as arguments and
> returns the sum of the squares of the two larger numbers ?

Chapter 1, exercise 1.3, page 21, of the "Structure and Interpretation of
Computer Programs", by Abelson, Sussman (_and_ Julie Sussman).

Assuming your instructor is using the second edition, of course.

However, I do think that your instructor will expect to see _Scheme_ code
for this function, and since you chose to post in c.l.lisp instead of
c.l.scheme, you should at least have mentioned this...

-- 
Arne Knut Roev <······@online.no> Snail: N-6141 ROVDE, Norway
=
The Gates of Hell shall not prevail:
Darkness now; then Light!