reset password
Author Message
rabbott
Posts: 1649
Posted 15:04 Oct 13, 2019 |

As I mentioned yesterday, the propagator (which we discussed in class Saturday and will discuss in class Monday) is unable to solve the problem on its own. But give it one more letter, and it finds it.  Here is a trace of assigned and unassigned variables. 

Problem: ['SEND', 'MORE', 'MONEY']
Columns:
4. (('C4', '_', '_'), ('C5', 'M'))
3. (('C3', 'S', 'M'), ('C4', 'O'))
2. (('C2', 'E', 'O'), ('C3', 'N'))
1. (('C1', 'N', 'R'), ('C2', 'E'))
0. (('C0', 'D', 'E'), ('C1', 'Y'))

Initial domains: {'M': {1}, 'C0': {0}, 'C4': {1}, 'C5': {0}, '_': {0}, 'C1': {0, 1}, 'C2': {0, 1}, 'C3': {0, 1}, 'S': {2, 3, 4, 5, 6, 7, 8, 9}, 'N': {0, 2, 3, 4, 5, 6, 7, 8, 9}, 'E': {0, 2, 3, 4, 5, 6, 7, 8, 9}, 'R': {0, 2, 3, 4, 5, 6, 7, 8, 9}, 'Y': {0, 2, 3, 4, 5, 6, 7, 8, 9}, 'O': {0, 2, 3, 4, 5, 6, 7, 8, 9}, 'D': {0, 2, 3, 4, 5, 6, 7, 8, 9}}

Initial state:
assigned: {'M': 1, 'C0': 0, 'C4': 1, 'C5': 0, '_': 0};
unassigned: ['N', 'E', 'R', 'Y', 'O', 'D', 'S', 'C1', 'C2', 'C3']

State after initial propagation
assigned: {'M': 1, 'S': 9, 'O': 0, 'C0': 0, 'C3': 0, 'C4': 1, 'C5': 0, '_': 0};
unassigned: ['E', 'D', 'Y', 'N', 'R', 'C1', 'C2']


Propagation after E = 5
assigned: {'M': 1, 'S': 9, 'O': 0, 'E': 5, 'D': 7, 'Y': 2, 'N': 6, 'R': 8, 'C0': 0, 'C1': 1, 'C2': 1, 'C3': 0, 'C4': 1, 'C5': 0, '_': 0};
unassigned: []

  SEND ->  9567
+ MORE ->  1085
------    -----
 MONEY -> 10652

{'M': 1, 'S': 9, 'O': 0, 'E': 5, 'D': 7, 'Y': 2, 'N': 6, 'R': 8}

Solution found after 4 assignments!

Process finished with exit code 0
 

The initial state is the information we give it: M = 1; C4 = 1. C0 and C5 are variables for the carry into the left-most column and the carry out of the rightmost. They are both set to 0. '_' is an anonymous variable that fills in the open positions to the left of SEND and MORE. Given these additional variables, all the columns have the same structure.

A single propagation finds S = 9, O = 0, and C3 = 0.

If we order the variables so that E is the next one to be given a value, the search function will try E = 2, E = 3, E = 4, and E = 5. The propagator finds that E = 2, 3, or 4 leads to a contradiction. When we try E = 5, the propagator finds the rest of the values. So the 4 trial assignments to E are all that are required to solve the problem.

Since E appears more often than any other letter, it makes sense to try it after the first propagation. In fact, that heuristic succeeds for this problem.

Update. Interestingly, It also gets the solution after 4 assignments if you put Y before E.  But the reason is that it first assigns Y = 2. Finding that to be consistent, it goes on to E. Since 2 is taken it tries E from 3 to 5, at which point it gets the solution. So putting Y first simply eliminates one of the possibilities for E, thereby using the same number of assignments. 

 

Last edited by rabbott at 17:46 Oct 13, 2019.