Search code examples
prologclpfd

Prolog arithmetic syntax


How to define a as a integer/float number ?

I want to find the results of a+b+c+d=10 where a,b,c,d is integer and >=0.


Solution

  • Here is a simple, modern, pure Prolog, non-CLP-library solution:

    range(X):-
            member(X,[0,1,2,3,4,5,6,7,8,9,10]).
    
    ten(A,B,C,D):-
            range(A),
            range(B),
            range(C),
            range(D),
            10 =:= A + B + C + D.