All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Find All Numbers (Posted on 2006-07-25)
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.

 No Solution Yet Submitted by Ravi Raja No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
 Solution (using computer) | Comment 1 of 7
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

 Posted by Robby Goetschalckx on 2006-07-25 11:33:30

 Search: Search body:
Forums (0)