Another Word Puzzle (words)
Problem
: Assign all digits (0 to
9)
each to a dierent letter in the following words to
make the numerical equality true (see [2]):
ONE + ONE + TWO + TWO + THREE + ELEVEN = TWENTY
This problem is similar to the problem in sendmore, however the modeling approach
will be dierent.
Modeling Steps
We introduce a set
i={
O N E T W H R L V Y} of the ten dierent letters used above.
Since there is a one-to-one correspondence between the ten letters and the digits from
to
9
we can also use the set as the set for the digits, denoted as
0
j.
xi,j for each letter-digit-combination, that is, xi,j = 1 if
letter i is assigned to digit j , otherwise xi,j = 0. For example, x3,2 = 1 means, that
the third letter (which is E) is assigned to the second digit (which is 1 (since 0 is the
rst digit). (We suppose that the letters and the digits are given as ordered sets.)
1. We use a binary variable
2. Each letter can only be assigned to exactly one single digit, and each digit is assigned
to a single letter. Hence:
X
xi,j = 1
for all
i,
j
X
xi,j = 1
for all
j
i
3. For each word (one,
two, three, eleven, and twenty
P) we build an expression
i be a letter, then j (j − 1) · xi,j is the digit
which represents the letter i. Why? According to the rst constraint, exactly one
xi,j over all j can be 1 for each letter i. Multiplying each term in the sum by j − 1
to represent its numerical value. Let
results in an expression with exactly one term in the sum that is dierent from zero,
hence it is the digit
j.
4. For a word (for example
letter
O)
by
100,
senting the letter
one),
we must multiply the rst digit (representing the
the second (representing the letter
E)
by
1,
N)
by
10
and the third (repre-
to express the numerical representation of the word
one
in decimal notation. It is represented by the expression:
X
(j − 1) · (100xO,j + 10xN,j + xE,j )
j
Similarly for the other expressions.
5. Each expression is given a name, say
one,
etc.
6. These expression names are then used in the constraint imposing the word addition:
one + one + two + two + three + eleven = twenty
7. We only need a feasible solution.
The complete model code in LPL for this model is as follows (see [1]):
1
Listing 1: The Model
model words "Another Word Puzzle";
set i,j := [O N E T W H R L V Y];
binary variable
x{i,j} "Does letter i represent digit j or not?";
expression
one:
sum{j}(j-1)*(100*x[’O’,j]+10*x[’N’,j]+x[’E’,j]);
two:
sum{j}(j-1)*(100*x[’T’,j]+10*x[’W’,j]+x[’O’,j]);
three: sum{j} (j-1) * (10000*x[’T’,j]+1000*x[’H’,j] +
100*x[’R’,j]+10*x[’E’,j]+x[’E’,j]);
eleven: sum{j} (j-1)*(100000*x[’E’,j]+10000*x[’L’,j]+
1000*x[’E’,j]+100*x[’V’,j]+10*x[’E’,j]+x[’N’,j]);
twenty: sum{j} (j-1)*(100000*x[’T’,j]+10000*x[’W’,j]+
1000*x[’E’,j]+100*x[’N’,j]+10*x[’T’,j]+x[’Y’,j]);
constraint
A{i}: sum{j} x = 1 "Each letter is one single digit";
B{j}: sum{i} x = 1 "Each digit is one single letter";
C: one + one + two + two + three + eleven = twenty;
--D: twenty <= 847180-1;
--D: twenty <= 837280-1;
--D: twenty <= 645863-2;
--maximize obj: twenty;
--Writep(obj);
solve;
Write{i}(’%s = %d\n’, i, argmax {j}x-1);
end
Solution
: An assignment of the 10 digits to the 10 dierent letters is as follows:
O = 1 , N = 7 , E = 5 , T = 6 , W = 0
H = 8 , R = 9 , L = 3 , V = 2 , Y = 4
giving:
ONE + ONE + TWO + TWO + THREE + ELEVEN = TWENTY
175 + 175 + 601 + 601 + 68255 + 535957 = 605764
Question
(Answer see )
1. Is the solution unique? Are there other possible assignments?
2. What is the smallest value for
TWENTY
?
3. How many solutions are there?
4. Build a new word puzzle and solve it. I propose (in German words) the following
nice addition:
EINS + ZWEI + DREI = SECHS
(This expression means one + two + three = six, and the words are in German).
How many dierent solutions are there?
Answer
(Question see )
2
1. The solution is not unique. Just minimize
x[1,2]
to nd another solution.
2. To nd the smallest value, replace the minimizing function by
minimize obj: twenty;
3. There exist 4 solutions. First, minimizing
imizing
twenty,
its value is
847180.
twenty, the value is 605764.
Next, max-
In a third optimization, keep the maximizing
function and add the constraint
constraint D: twenty <= 847180-1;
837280. Modifying the constraint to: twenty <= 837280-1,
solution 645863. Repeating the same procedure gives the same solu-
The solution is now:
generates the
tion we found when minimizing. Therefore, all solution have been found so far.
1
4. There exist a couple of solutions! The model formulated in LPL is given at word1
:
model words1 "A Word Puzzle II";
set i,j := [E I N S Z W D R C H];
binary variable x{i,j} "Letter i represents digit j?";
expression
eins: sum{j} (j-1)*(1000*x[’E’,j]+100*x[’I’,j]+
10*x[’N’,j]+x[’S’,j]);
zwei: sum{j} (j-1)*(1000*x[’Z’,j]+100*x[’W’,j]+
10*x[’E’,j]+x[’I’,j]);
drei: sum{j} (j-1)*(1000*x[’D’,j]+100*x[’R’,j]+
10*x[’E’,j]+x[’I’,j]);
sechs: sum{j} (j-1)*(10000*x[’S’,j]+1000*x[’E’,j]+
100*x[’C’,j]+10*x[’H’,j]+x[’S’,j]);
constraint
A{i}: sum{j} x = 1 "Each letter is one digit";
B{j}: sum{i} x = 1 "Each digit is one letter";
C: eins + zwei + drei = sechs;
solve;
Write{i}(’%s = %d\n’, i, argmax{j} x-1);
end
2
A model that returns and counts all solutions is given at words2 .
Try also the following puzzles:
VINGT + CINQ + CINQ = TRENTE
EIN + EIN + EIN + EIN = VIER
DONALD + GERALD = ROBERT
SATURN + URANUS + NEPTUNE + PLUTO = PLANETS
WRONG + WRONG = RIGHT
1 http://lpl.unifr.ch/lpl/Solver.jsp?name=/word1
2 http://lpl.unifr.ch/lpl/Solver.jsp?name=/words2
3
References
[1] T. Hürlimann. Reference Manual for the LPL Modelling Language, most recent version.
www.virtual-optima.com.
[2] Clare
Nolan.
http://www.chlond.demon.co.uk/academic/puzzles.
html.
4
© Copyright 2025 Paperzz