View Single Post
  #153 (permalink)  
Old 22-May-2007, 06:47 PM
Celestial Mechanic's Avatar
Celestial Mechanic Celestial Mechanic is offline
Order of Kilopi
 
Join Date: Jun 2002
Location: Milwaukee, WI
Posts: 4,543
Default Time for a Boring Anecdote!

Quote:
Originally Posted by Celestial Mechanic View Post
Quote:
[Snip!] Fascinating. Nothing like thinking outside the box. Where ALL true Discoveries are found !!
But if you have no understanding of the box, how do you know you are thinking outside of it?
The more I think about it, the more the phrase "Think outside the box" disturbs me. Most of the time it is used to justify slovenly, uncritical thinking in the belief that the most "creative" solutions are the best. Here's a boring anecdote to illustrate my point.

More than 30 years ago (was it really that long ago?) I took a course at the university called "High Speed Computation". It was a rather free-wheeling, informal course in which problem sets were assigned, we would do as many as we could, but (most important thing!) we would explain how we did it. We were allowed to use whatever language we liked from the compilers offered at that time. This meant Fortran (WATFIV), PL/I, LISP, even BASIC. In the case of FORTRAN, we had access to the various subroutine libraries.

One problem we were assigned was this: to generate the set of all integers of the form 2k*3l*5n less than 1 million and list them in order. Everyone else in the class chose to generate an array containing (say) all the powers of 2, then add the products of these with powers of three to the array, call the sort routine from the subroutine library, then multiply these numbers by powers of 5, and call the sort routine one last time.

But I had an insight: if x is an element of this set, then so are 2*x, 3*x, and 5*x. I know that 1 is an element of the set, so the next element must be the minimum of 2*1, 3*1, and 5*1, so the next element is 2. Knowing this, the next element must be the minimum of 2*2, 3*1, and 5*1, which is 3. The next element must be the minimum of 2*2, 3*2, and 5*1, which is 4. We have to be careful whenever we have two or all three of these candidates equal, because we must advance the index for each of the candidates to the next element of the set. For example, 2*15, 3*10, and 5*6 are 30, so after adding 30 to the array we must advance the index of each of these numbers to the next one, so that the next candidate is the minimum of 2*16, 3*12, and 5*8, which is 32.

The professor was amazed. No one had thought of actually generating them in order before. Now in the past, I used to describe this as "out of the box" thinking, and I suppose it is "out of the box" thinking if you consider the box to be "Use FORTRAN and the math subroutine libraries". But I realize now that "the box" was really the definition of the set, and that understanding "the box" was the key to realizing that its membership could be generated inductively from its first member, the number one.

BTW: My program was written in crummy FORTRAN-esque spaghetti-code about 30 lines long. One of my classmates was so impressed by my algorithm that he rewrote it in RATFOR (an early structured version of FORTRAN) and got it down to 18 lines. That impressed me enough to learn structured programming and I haven't looked back.
__________________
Microsoft is over if you want it.

The bar has been lowered for the promotion of ATM ideas; the bar for the acceptance of ATM ideas must remain high.