## Puzzle 1## The ProblemSome time ago the following puzzle was posed in the newsgroup sci.math.symbolic.
Let E,
ONE must be a square, and In this puzzle the expression "THREE+1" is defined as the sum , the remaining constraints being defined in the same way. Determine E, F, H, N, O, R, T, U, and W. ## The SolutionA brute force solution would be to check for all possible values of E, F, H, N, O, R, T, U, and W (each ranging independently from 0 to 9) to fulfill the conditions. This would mean to check nearly one billion cases. Although certainly doable on a 1999-vintage computer, it is not a solution that can be efficiently generalized to more variables. In the following, we will implement a solution that is not specifically tailored to this problem, but which can be used to solve any problem of this kind. Let us first calculate all possible sets of conditions arising from the puzzle. Every row in the following table is one possibility for the four conditions to be fulfilled.
These are 48 possible combinations.
The function
and ` ` .
Here is an example of all nonnegative integer square numbers between 0 and 1234.
Given an expression of the form different digit. The result of is a list of possible realizations in the form of replacement rules.
`allPossibleDigitRealizations`
Here is an example.
Both realizations for the letters give a square.
The function attribute here to keep the arguments from being evaluated in case one argument is empty, to avoid unnecessary computations.
`HoldAll`
Let us again look at an example. Here are the possible digit realizations for to be a square.
`two+3`
The following 14-digit realizations are the compatible realizations.
Now we can take a set of conditions from chooses
`allConditionCombinations`
We get a nontrivial solution. Now let us check all other combinations of
No other solutions have been found. (The last evaluation effectively searched the entire solution space of the puzzle in less than a second, on a 1999-vintage computer.) Let us finish by substituting the calculated result into the original condition to check that the solution is OK.
Converted by Mathematica
October 5, 1999
[Next Page] |