• subscribe
June 26, 2002 12:00 AM

Missing Numbers

SQL Server Pro
InstantDoc ID #25103
Downloads
25103.zip

Could any form of this puzzle still have a solution if the upper boundary isn't considered to be finite? Yes. For example, if you could represent the missing numbers in any form you wanted, you might represent them as ranges of numbers. The query in Listing 6 does just that, calculating the begin_range values as follows:

Given that n is a value in Test1, begin_range =
n + 1 if no row exists in Test1 where a = n + 1.

Similarly, the query calculates the end_range values as follows:

Given that n is a value in Test1, end_range = 
n - 1 if no row exists in Test1 where a = n - 1.

To match begin_range values with their corresponding end_range values, the query selects for each begin_range value the minimum end_range value that's greater than or equal to the begin_range value. Although Listing 6's query gives a solution to the missing numbers puzzle with an unknown boundary, it doesn't meet the format requirement for the query output.

Worth the Effort?
Knowing how talented Isaac Blank is with SQL, I knew I was facing a tough puzzle. I also knew that I might run into a dead end. You might wonder whether trying to solve a problem that might not have a solution is worth the effort. I think it is.

Pierre de Fermat, a seventeenth-century mathematical genius, wrote notes in the margins of a book. In his notes, he claimed that he could prove that the equation xn + yn = zn has no solution where x, y, and z are natural numbers and n > 2. However, the book's margins weren't wide enough for him to write down the solution. Fermat never published his proof, so some mathematicians are still skeptical that he had one. Mathematicians tried to find a proof for more than 350 years, until British mathematician Andrew Wiles discovered one in 1995.

My father is one of the mathematicians who spent years trying to solve Fermat's Last Theorem. He thought about it wherever he went. If you ask my father how he feels about having spent so much time on a problem without finding the proof, he says it was well worth the study. Although he didn't find the solution, he polished his skills in Number Theory and invented many new techniques of his own. The puzzle in this article is nowhere close in scale to Fermat's Last Theorem, but whenever you try to solve an SQL puzzle, even if it has no solution, you polish your skills. And the attempt can be well worth the effort.



ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here