Lecture 8
Lecture 8
2. If the union of the constraints discovered above defines a solution, then quit and report the solution.
3. If the union of the constraints discovered above defines a contradiction, then return failure.
4. If neither of the above occurs, then it is necessary to make a guess at something in order to proceed. To
do this, loop until a solution is found or all possible solutions have been eliminated:
(a) Select an object whose value is not yet determined and select a way of strengthening the constraints on
that object.
(b) Recursively invoke constraint satisfaction with the current set of constraints augmented by the
strengthening constraint just selected.
66
A Cryptarithmetic Problem
67
Solving a Cryptarithmetic Problem
68
From column 5, M = 1 since it is the only carry-over possible from the sum of two
single digit numbers in column 4.
Since there is a carry in column 5, and M = 1, then O = 0
Since O = 0 there cannot be a carry in column 4 (otherwise N would also be 0 in
column 3) so S = 9.
If there were no carry in column 3 then E = N, which is impossible. Therefore there is
a carry and N = E + 1.
If there were no carry in column 2, then ( N + R ) mod 10 = E, and N = E + 1, so ( E
+ 1 + R ) mod 10 = E which means ( 1 + R ) mod 10 = 0, so R = 9. But S = 9, so
there must be a carry in column 2 so R = 8.
To produce a carry in column 2, we must have D + E = 10 + Y.
Y is at least 2 so D + E is at least 12.
The only two pairs of available numbers that sum to at least 12 are (5,7) and (6,7) so
either E = 7 or D = 7.
Since N = E + 1, E can't be 7 because then N = 8 = R so D = 7.
E can't be 6 because then N = 7 = D so E = 5 and N = 6.
D + E = 12 so Y = 2.