I'm taking a programming course and the professor just lightly skimmed over Prolog due to lack of time. Anyways, he suggested we research it on our own. I came across a Cryptarithmetic program that is supposed to calculate? AM+PM = DAY. I do not know what is supposed to be added as input in the SWI interpreter and what should be received as the correct output...If this makes any sense?
I tried...
solve([AM],[PM],[DAY]).
That does nothing. Any help on what the correct input would be for AM+PM = DAY or something similar would be great! Here is the program I was playing with...
solve([A,M,P,D,Y]):-
select(A,[0,1,2,3,4,5,6,7,8,9],WA), % W means Without
not(A=0),
select(M,WA,WMA),
select(P,WMA,WMAP),
not(P=0),
select(D,WMAP,WMAPD),
not(D=0),
select(Y,WMAPD,WMAPDY),
DAY is 100*D+10*A+Y,
AM is 10*A+M,
PM is 10*P+M,
DAY is AM+PM.
Please keep in mind that we only had two classes on Prolog so I know next to nothing!
Scott
solve(X)
, it gives you the possible results forA
,M
,P
,D
andY
in a list of length 5. – Patrick J. S.solve([A, M,P,D,Y]).
hope that helps. It would be easier if you say what you don't understand. Prolog gives you one solution for the problem, if you press <kbd>space</kbd> you'll get the other ones. – Patrick J. S.