Quote:
>I have a question. I'm not sure if you guys have heard of Alphametic
>puzzles. But if you haven't it's like America = Fifty + States There is
>a number that corresponds to each letter (like a cryptogram puzzle). Now, i
>was trying to write a program in QBasic (1.1) and i'm not getting very far.
>Can someone help me write the code to find the numbers in these puzzles?
>-Graham
Graham
What you can do, in a brute force solution, is write a program that
contains 10 or so nested loops - probably FOR loops.
You have ten letters, and I assume the puzzle is to assign a single
decimal digit from 0 to 9 to each letter such that the equality is met
by the numbers composed using this substitution .
In puzzles like this, usually the digits can only be assigned once
only, but sometimes they can be assigned multiple times, ie. maybe
both a and m represent the digit 0. If it is not specified, try for a
solution with unique assignments. If that does not work, try for a
non-unique-assignment result, but that is flakey - one should make a
puzzle like this!
Each time you cycle thru the 10 letter assignments, you must test to
see if the resulting numbers produce the equality.
Do this by composing the required numbers from the current pattern of
letter assignments for this iteration:
america = 1000000*a + 100000*m + 10000*e + . . . etc
fifty = 10000*f + 1000*i + . . . etc
states = 100000*s + . . . etc
Your test will be if fifty + states equals america, then you have
found the correct letter assignment. If not, then do the next cycle
thru the digit to letter assignments and test again.
Run the sucker till it finds the answer.
Go make some coffee.
Hint:
So you can tell its actually working, optionally display the
assignements and results on screen while it's running, so you can get
an idea if you've got your assignments procedure correct, and to see
how long it is taking. When you are convinced your method is
flawless, bypass the display if it making the whole thing run too
slowly.
Have fun.
For an PhD, you could reverse the testing and find new puzzles.
Hook into a dictionary lookup to test your results so you don't have
to eyeball every one to see if it's composed of real words.
- Tom