% Using CLP for SEND+MORE=MONEY problem

:- use_module(library(clpfd)).

% put in 0 for the carry
add(A,B,C) :- add(A,B,C,0).

add([],[],[],0).
add([A|As],[B|Bs],[C|Cs],Carry) :-
   add(As,Bs,Cs,PrevCarry),
   A in 0..9,
   B in 0..9,
   C #= (A + B + PrevCarry) mod 10,
   Carry #= (A + B + PrevCarry)/10.

all_different([]).
all_different([X|L]) :-
   ad(X,L),
   all_different(L).

ad(_,[]).
ad(X,[Y|L]) :- X #\= Y, ad(X,L).
