Featured Post

Step Wise Project Planning

Planning is the most difficult process in project management. The framework described is called the Stepwise method to help to distinguis...

  1. Home

WAP to solve a given cryptographic problem

WAP to solve a given cryptographic problem.
                                                              S  E  N  D
                                                          + M O  R  E
                                                        M  O  N  E  Y
domains
il=integer*

predicates
member(integer,il)
delete(integer,il,il)
go

clauses
go if
L=[0,2,3,4,5,6,7,8,9],
M=1,
member(D,L),
delete(D,L,L1),
member(E,L1),
delete(E,L1,L2),
member(Y,L2),
delete(Y,L2,L21),
member(N,L21),
delete(N,L21,L3),
member(R,L3),
delete(R,L3,L4),
member(O,L4),
delete(O,L4,L5),
member(S,L5),
delete(S,L5,_),

Num1=S*1000 + E*100 + N*10 + D,
Num2=M*1000 + O*100 + R*10 + E,
Result=M*10000 + O*1000 + N*100 + E*10 + Y,
Result=Num1+Num2,
write(" ",S,E,N,D),write("\n 1",O,R,E),write("\n1",O,N,E,Y),fail.

member(X,[X|_]).
member(X,[_|T]) if member (X,T).
delete(X,[X|T],T).
delete(X,[Y|T],[Y|Z]) if delete(X,T,Z).

Output:-

Goal: go
   9567
  1085

10652 No
Previous
Next Post »