Solving an alphametic


An alphametic consists of an arithmetic problem, where the digits 0 through 9 have been replaced by letters. Your job is to find the digit that each letter represents and replace it, one by one, thus breaking the code used.

Letters always represent the same digit throughout a puzzle, so if C represents 8 in one place, it
represents 8 everywhere. Of course, each puzzle uses a different representation. Leading zeroes are not allowed, and each puzzle has a unique solution.

The program "Crack a Puzzle Online" facilitates enormously the replacement of the letters with the corresponding digits, a tedious job if made by hand. Wrong substitutions will not be admitted, being signalled by the warning "Incorrect solution!". Double attention must be paid when solving the rare alphametics in which the letter "O" stands for the digit "0". The resemblance of both characters can get you confused!

At the right lower corner of the screen you see a little narrow window that shows the current state of the key, a table consisting of each of the letters used in the alphametic, paired with its numerical equivalent. There you have a record of which digits have already been assigned and the ones still free. This tool helps testing possible values for next assignment.

Hints will be given by double-clicking the letter you want to see disclosed, though beware, this is a tool of last resort to be scarcely used, otherwise it can steal the exhilaration you derive from solving puzzles, that is, the feeling of accomplishment after hard reasoning to "crack the code".

The program detects the end of the solving process, when the last substitution is being assigned, issuing a "Congratulations!" message, and asking about the userīs intentions - to solve another alphametic or to quit.


Example

Letīs take this very easy problem : AD + DI = DID and work it out in detail.

The initial configuration is:

                A D
              + D I
             ------- 
              D I D

D + I = D   is the units column on the right side
A + D = I   is the tens column in the middle
D (alone in the total)   is the hundreds column on the left side

You can guess that D in the hundreds column equals 1 because it is the "carry 1" from the tens column. In other words, A + D = I + 10 transfers a "carry 1" to the total in the hundreds column. Can you see it?

Now you substitute all Dīs for 1, and the addition becomes:


                A 1
              + 1 I
             ------- 
              1 I 1

Take a look at the units colum, and you will guess that I equals zero. In this column you see that 1 + I = 1 so, if you try all digits not yet decoded, you will find that the only one that matches this pattern is zero. See it?


Now you replace all Iīs with 0, and the addition becomes:

                A 1
              + 1 0
             ------- 
              1 0 1

Then observe the tens column where we have A + 1 = 10. So, A must be 9 to fit this pattern. And substituting the A for 9 we have the whole problem solved, that is:

                9 1
              + 1 0
             ------- 
              1 0 1