This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/pyswip/examples/sendmoremoney/money.pl
2010-06-01 00:33:32 +01:00

23 lines
708 B
Prolog

% SEND + MORE = MONEY
% Adapted from: http://en.wikipedia.org/wiki/Constraint_programming
:- use_module(library(clpfd)).
sendmore(Digits) :-
Digits = [S,E,N,D,M,O,R,Y], % Create variables
allin(Digits, 0..9), % Associate domains to variables
S #\= 0, % Constraint: S must be different from 0
M #\= 0,
all_different(Digits), % all the elements must take different values
1000*S + 100*E + 10*N + D % Other constraints
+ 1000*M + 100*O + 10*R + E
#= 10000*M + 1000*O + 100*N + 10*E + Y,
label(Digits). % Start the search
allin([],_).
allin([Pos|Board],D) :-
Pos in D,
allin(Board,D).