in reply to Words that equal numbers
In essence what one wants to do is to allocate the numbers 0 - 9 over 10 or less letters. To make it easier we will allocate the figures 0 to 9 over exactly 10 letters (we will make up the missing letters and drop them when appropriate).
Of course we may allocate each letter only once, but I think that using a clever algorithm to make sure that each letter is not used more than once will take more time than using real brute force and dropping "wrong" solutions afterwards.
So I would set up a for loop starting with '0123456789' till '9876543210' with a step of 1 and directly allocating the first digit to the (alphabetically) first letter used in your equation and so on. (Perhaps it is easier to start with the last digit in order not to involuntarily shift the whole pattern if it starts with a zero)
Then checking if the equation holds and if it holds checking if no digit has been used more than once.
Thus you delay at lot of "expensive" tests and logic until they are really necessary.
If you optimise the allocation of the digits to the letters and you hard code the testing of the equation, it should be possible.
CountZero
"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Words that equal numbers
by tall_man (Parson) on Jan 18, 2003 at 14:35 UTC | |
by CountZero (Bishop) on Jan 18, 2003 at 23:35 UTC | |
by tall_man (Parson) on Jan 19, 2003 at 01:29 UTC | |
by CountZero (Bishop) on Jan 19, 2003 at 09:06 UTC |