digit(D) :- between(0,9,D).

pairAdd10(D1,D2) :-
	digit(D1),
	digit(D2),
	D1 + D2 =:= 10.

allPairs(L) :- findall(p(D1,D2),pairAdd10(D1,D2),L).

palindrome(S) :-
	digit(D1), digit(D2), digit(D3), digit(D4), % generate
	S is (10*D1+D2)*(10*D3+D4),
	S >= 1000,                                % test
	mod(div(S,1000),10) =:= mod(S,10),        % 1st = 4th
	mod(div(S,100),10) =:= mod(div(S,10),10). % 2nd = 3rd

allPalindromes(S,L) :- findall(P,palindrome(P),S),length(S,L).  % 118 solutions

setPalindromes(S,L) :- setof(P,palindrome(P),S),length(S,L). % 36 unique

palindromeD(S,[D1,D2,D3,D4]) :-
	digit(D1), digit(D2), digit(D3), digit(D4), % generate
	S is (10*D1+D2)*(10*D3+D4),
	S >= 1000,                                % test
	mod(div(S,1000),10) =:= mod(S,10),        % 1st = 4th
	mod(div(S,100),10) =:= mod(div(S,10),10). % 2nd = 3rd

