Find all four–digit numbers in which the product of the digits is equal to the sum of the digits, and the number itself is divisible by the sum of its digits.

Or rather, no solution, except for the trivial 0000 (which might not be considered a true four-digit number).

I used the following prolog code:

sol([A,B,C,D]) :-

List = [1,2,3,4,5,6,7,8,9],

member(A,List),

member(B,List),

member(C,List),

member(D,List),

Prod is A*B*C*D,

Sum is A+B+C+D,

Prod = Sum,

Number is A*1000+B*100+C*10+D,

modulo(Sum,Number,Mod),

Mod = 0.

modulo(N,M,N) :-

N < M,

!.

modulo(N,M,Res) :-

NN is N-M,

modulo(NN,M,Res).

With the following result:

?- sol(L).

No