You write: "My program compiles, but the function does not execute:"
solve([A, M1, M2, P, D, Y]):- D is 1, A/=0,
Not surprising. First of all, there is no /= operator in Prolog. I assume you mean \= . But A \= B means that "A cannot be unified with B". In your case, B is 0, but A is an undefined logical variable. It can be combined with anything. You should use \= to check for inequality, after all the logs have been involved!
So A \= 0 does not work . (Another thing, M1=M2 superfluous, you can just use M everywhere).
A common tool for solving such puzzles is the unique choice of domain narrowing :
selectM([A|As],S,Z):- select(A,S,S1),selectM(As,S1,Z). selectM([],Z,Z).
With it, your puzzle is simple
solve([A,M,P,D,Y]):- selectM([A,P,D],[1,2,3,4,5,6,7,8,9],R), % R is the remaining domain selectM([M,Y],[0|R],_), % don't care what remains 10*(A+P)+M+M =:= 100*D+10*A+Y.
You have the right idea to find out the purpose before looking for where it is possible. Using your approach, it can be written as
solve([A,M,P,D,Y]):- selectM([M,A],[0,1,2,3,4,5,6,7,8,9],R), A =\= 0, Y is (M+M) mod 10, % AM+PM=DAY C1 is (M+M)
Again, we must select A before testing its value.