Consider the well-known SEND MORE MONEY puzzle. Given eight letters S, E, N, D, M, O, R and Y, one is required to assign a digit between 1 and 9 to each letter, such that different letters are assigned unique different digits and the equation SEND + MORE = MONEY holds. The following program specifies the problem.

sendmory(Vars):- Vars=[S,E,N,D,M,O,R,Y], % variable generation Vars :: 0..9, alldifferent(Vars), % constraint generation S #\= 0, M #\= 0, 1000*S+100*E+10*N+D + 1000*M+100*O+10*R+E #= 10000*M+1000*O+100*N+10*E+Y, labeling(Vars). % labelingThe call

- Finite-domain variables
- Table constraints
- Arithmetic constraints
- Global constraints
- Labeling and variable/value ordering
- Optimization

Neng-Fa Zhou 2013-01-25