Appendix 1
Possible Solutions

Since the first edition of this book, the single question I have been asked the most is “Where are the answers to the exercises?”

My reluctance centered around the first occurrence of the word the in that question.

The answers? There’s more than one right answer, of course. Many, many more. These aren’t math problems. Even the first exercises, which are sort of like math problems, have many possible solutions. If, instead of writing a program about orange trees or the minutes in a decade, you were asked to write a poem about them, it would be silly (if not downright harmful) to include “the answers.”

That was my reasoning, anyway. Kind of stupid, in retrospect—while these aren’t math problems, neither are they poems.

Still, I’m really attached to the idea that there’s no one right answer here, so I did a few things to drive that point home. First, notice the title to this appendix: possible solutions, not the solutions.

Then I went through and did each exercise twice. Yes, seriously. The first time is to show just one possible way that you could have done it, given what you have learned up to that point in the book. The second time is to show you how I would do it, using whatever techniques tickled my fancy. Some of these techniques are not covered in this book, so it’s OK if you don’t understand exactly what’s going on. These programs tend to be more complex but also shorter (sometimes much shorter) and sometimes more correct or robust. Often cuter. (I like cute code.)

Ignore them or study them as you prefer.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.75.10