SEND+MORE=MONEY
Prolog 人工智能语言中文论坛---打造优质Prolog学习交流园地
fstDgt(D) :- between(1, 9, D).
digits([]).
digits([H|Rest]) :- between(0, 9, H), digits(Rest).
:- fstDgt(S), fstDgt(M), digits([E,M,D,O,R]).
notRedundant([]).
notRedundant([H|Rest]) :-
not(headRedundant([H|Rest])),
notRedundant(Rest).
headRedundant([H|Rest]) :-
member(H, Rest).
checkAdd(Send, More, Money) :-
fstDgt(S), fstDgt(M), digits([E,N,D,O,R]),
Send is 1000*S+100*E+10*N+D,
More is 1000*M+100*O+10*R+E,
Money is Send+More,
M =:= Money div 10000,
O =:= Money div 1000 - 10*M,
N =:= Money div 100 - (100*M+10*O),
E =:= Money div 10 - (1000*M+100*O+10*N),
Y is Money - (10000*M+1000*O+100*N+10*E),
notRedundant([S,M,E,N,D,O,R,Y]).
:- bagof(Send+More=Money, checkAdd(Send, More, Money), Results), write(Results), nl.
您在这个论坛的权限:
您不能在这个论坛回复主题