Search code examples
prologclpfd

Prolog arithmetic


If I had the following SWI Prolog queries and answers

[A,B,C] ins 1..3, A#= B + C.

And needed to select from below which were incorrect:

A in 2..3,
B in 1..3,
C in 1..3.

Would I be correct in thinking that A in 2..3 is not possible as in no case can A = 3?


Solution

  • Actually, what the constraint does, is to reduce the domains of B and C.

    Since their sum must be in range 1..3, and both have range 1..3. they must assume values in range 1..2.

    Then A in 2..3 it's the only right answer there.