## benjaminf 3 years ago Ex1.3 in SICP: We're supposed to define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. How do you treat the case {0,0,1}? In that case there _aren't_ two larger numbers. If you tried this question did you have to make (unjustified?) assumptions? Thanks.

1. azka.niazi

2. azka.niazi

sorry, thats \[0^{2}+1^{2}\]

3. benjaminf

Okay, you're right. But just to be annoying about it...what if the purpose of this excise was to start building a program that would help you choose the shortest traveling distance between two islands (via other islands.) Then it's not just a matter of what the sum-of-squares value is, but also how you got it, i.e. which numbers (directional parameters) you chose. At least, that what it seems like to me! but I'll be using your interpretation, so thank you.

4. azka.niazi

Well, it is not annoying actually. Answering questions has its own pleasure. I must admit some confusion about this shortest distance thing you mentioned. Not that I don't understand the problem, but because the nature of the problem seems very different to me. Ex 1.3 is a far simpler problem (it is chapter 1 after all!). Other than that shortest distance problem is quantified in terms of numerical values which is the sum of all the distances it has to cover over a path. The least sum out of all possible paths will be the answer. I think you are worried about how to keep track of the path itself (which has the shortest distance). There are algorithms for that too - Google-ing might help. But more important are the Data Structures which are used to represent maps/graphs. Anyway, the book, in a later chapter, does talk about trees and graphs. p.s. you're welcome! :)

5. benjaminf

I thought the distance example would be handy to show that (0,0,1) and (0,1,0) are different, maybe not when you're calculating the sum of squares, but definitely when you have to make a choice between them. But that, like you said, is a different kind of problem. Instead, the exercise just asks for the sum of squares of the two larger numbers. You rightly point out that it doesn't matter which {0} I pick, the answer is the same, and I went with that for my solution. But I think it's also valid to say that in a case where there _aren't_ two larger numbers it's _not possible_ to return the sum-of-squares for two larger numbers and returning some version NOT DEFINED might also be okay.

6. azka.niazi

yes you're absolutely right. i have no reason to disagree.