?- use_module(library(clpfd)). % step 1: declare domains of the variables % step 2: post the problem constraints % step 3: search for a solution % % call: ?- money(A,[]). money([A,B,C,D,E,F,G,H,I], Type) :- domain([A,B,C,D,E,F,G,H,I], 1, 9), % step 1 % S#>0, % M#>0, all_different([A,B,C,D,E,F,G,H,I]), % step 2a sum(A,B,C,D,E,F,G,H,I), % step 2a labeling(Type, [A,B,C,D,E,F,G,H,I]). % step 3 sum(A,B,C,D,E,F,G,H,I) :- A+B+C #= D+E+F, D+E+F #= G+H+I, A+D+G #= B+E+H, B+E+H #= C+F+I, A+E+I #= C+E+G.