Let's start with a basic problem:
ONE
ONE
ONE
+ONE
----
TEN
The idea is to substitute all the alphabetic characters with unique digits and have a valid mathematical statement. Thus we have each character
from 0 to 9, but
O may not be zero and none of O,N,E or T must be the same. We need to remember that there could be "carry overs" when adding the digits above the line.
We can now write above in another way:
(1) | E*4 = N + 10*b | (Where b is the "carry over") |
(2) | N*4 + b = E + 10*a | (Where a is the "carry over") |
(3) | O*4 + a = T | (Here is no "carry over") |
Algebraic approach
We first need to take into account that no "carry over" can be more than 3. (Max digit would be 9 and 9*4 = 36 which means a "carry over" of 3)
We know that 1 < T < 10 and 1 < O. But O must be less than 3, seeing that 3*4 = 12 and we are restricted to T < 10. Now we have O to be
either 1 or 2.
We can rewrite (1) above and then combine it with (2):
(4) | N = E*4 - 10*b | (Swapped left and right side and take 10*b over) |
(5) | E*16 - 40*b + b = E + 10*a | (Replace N*4 in (2) with (4)*4) |
(6) | E*15 = 39*b + 10*a | (Take Es to left side and all a and b elements to right side) |
If b is taken to be zero (no "carry over" when the Es are added together) then E*15 = 10*a. If E is zero then a must be zero but
then N is also zero which breaks our original premises. The next possible solutions is when a=3, then E*15 = 10*3 or E = 30/15 = 2.
With E=2 we get N=E*4=8 (with no "carry over"). Now we can apply the values for E and N to (2) and we get 8*4 + 0 = 2 + 10*a or 32 = 2 + 10*a which we can write as a = 30/10 = 3, which we already determined (this just confirms it).
Now we substitute a into (3) and get O*4 + 3 = T. We know from above that O can only be 1 or 2, but if O is 2 then T = 2*4+3 = 11 which won't work. Thus O can only be 1 and this leads to
1*4 + 3 = 7 = T.
Now we have enough to rewrite the original problem with digits:
182
182
182
+182
----
728
Search Approach
With this approach we will go through all combinations of digits for O,E,N and T until we get values that work. N and T can be determined once we have values for O and E.
Thus we only need to cover 9*9 = 81 combinations to search for an answer (remember that O and E must not be the same).
From above we know N = E*4 - 10*b also N = (E*4) mod 10, the carry = (E*4) div 10
Thus E = (carry + N*4) mod 10 and the new carry = (carry + N*4) div 10. This E must equal the original E.
Now T = O*4 + carry where we know O can be only 1 or 2
O | E | N | E2 | T | |
1 | 0 | 0 | 0 | 0 | N=2, so it's a no go |
1 | 2 | 8 | 2 | 7 | Got an answer |
For this simple example the "Search Approach" will definately be the fastest approach. When multiple variables need to be searched then searching can
be time intensive.
Programmatic Approach
A basic algorithm based on the Search Approach with some properties determined with the Algebraic Approach can help us to approach the problem with a program.
for O = 1 to 2
for E = 0 to 9
if (O <> E) then
tmp = E*4
carry = tmp div 10
N = tmp mod 10
tmp = carry + N*4
carry = tmp div 10
E2 = tmp mod 10
T = carry + O*4
if (N <> O) AND (N <> E) AND (E2 = E) AND (T < 10) AND (T <> O) AND (T <> E) AND (T <> N) then
print the results
stop the program
endif
else
break;
endif
endfor
endfor
Program Source