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.
You used a Fold Stone on max.
What's that? max is evolving?
<<da da da da da da
dadadadadadadada
dada dada!>>
Congratulations! max now accepts arbitrary number of arguments!
Name:
Anonymous2008-01-19 14:30
This is very easy. You should've been able to figure this out yourself.
(define (square a) (* a a))
(define (sum-of-squares a b) (+ (square a) (square b)))
(define (ex3 x y z)
(cond ((and (> y x) (> z x)) (sum-of-squares y z))
((and (> x y) (> z y)) (sum-of-squares x z))
((and (> x z) (> y z)) (sum-of-squares x y))))
It is simply a process of working out the smallest number, and then you know which two are the largest.
>>19
It's the best solution in this thread. That's not saying much, though.
>>20
REAL COMPUTER PROGRAMS ARE NOT WRITTEN IN LISP
Name:
Anonymous2008-01-19 16:31
>>21
ARE YOU STUPID OR SOMETHING. IT IS NOT A CHALLENGE TO DO SOMETHING USEFUL IN REAL LANGUAGES, IT IT HOWEVER TO DO IT IN RISPU. THANK YOU FOR YOUR ATTENTION.
(FUNNY FACT: I HAD NO IDEA I HAD THE CAPS LOCK ON WHEN WRITING >>20)
(FUNNY FACT: YOU JUST LOST THE GAME)
Name:
Anonymous2008-01-19 17:15
>>22
IT IT? >>21
No it's not, you are using a fucking sort algorithm.
Name:
Anonymous2008-01-19 19:30
<?php
function faggot(){$a=func_get_args();@array_pop(rsort($a));return(int)($a[0]*$a[0])+($a[1]*$a[1]);}
echo faggot(7,5,3)
?>
>>29
I do understand what >>4 posted. I used a variant of if a>b and b>c then a>c
where if a>b and b>c then a+b>c (where a and b are positive)
to solve it.