%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% The SEND + MORE = MONEY puzzle.
% Solve the equation by assigning a distinct digit between 
% 0 and 9 to each letter.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

:- use_module(library('clp/bounds')).

solve_puzzle(S,E,N,D,M,O,R,Y):-
    Digits = [S,E,N,D,M,O,R,Y],
    Digits in 0..9,
    all_different(Digits),
    S #>= 1, M #>= 1, 
    M*10000 + O*1000 + N*100 + E*10 + Y #=
    S*1000 + E*100 + N*10 + D + M*1000 + O*100 + R*10 + E.
%,
%    label(Digits).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/*
Example
 
?- solve_puzzle(S,E,N,D,M,O,R,Y).

S = 9
E = 5
N = 6
D = 7
M = 1
O = 0
R = 8
Y = 2 ;

No
*/

