Challenge 1: Three Variables Summing to 9 via CLP(FD) — Possible Solution ==================================================================== sum_demo.pl: :- use_module(library(clpfd)). Query: ?- X in 1..5, Y in 1..5, Z in 1..5, X + Y + Z #= 9, label([X, Y, Z]). X = 1, Y = 3, Z = 5 ; X = 1, Y = 4, Z = 4 ; X = 1, Y = 5, Z = 3 ; X = 2, Y = 2, Z = 5 ; X = 2, Y = 3, Z = 4 ; X = 2, Y = 4, Z = 3 ; X = 2, Y = 5, Z = 2 ; X = 3, Y = 1, Z = 5 ; ... (every combination of three values 1-5 summing to 9) Explanation: Each of X, Y, Z is declared as a domain variable ranging over 1..5, none of them assigned a concrete value yet. Posting X + Y + Z #= 9 immediately propagates that constraint across all three domains simultaneously -- for instance, no variable could ever actually be labeled 1 while the other two are both also forced below 4, since their combined maximum wouldn't reach 9, so CLP(FD) narrows the effectively-reachable combinations before label/1 even starts searching. label([X, Y, Z]) then backtracks through every concrete assignment that satisfies both the domain bounds and the sum constraint together, offering each one via ;, in the same pattern the chapter's own two-variable example demonstrated. WHY THIS WORKS AS AN ANSWER ------------------------------ This extends the chapter's own two-variable sum pattern to three variables and a different target sum, confirming the same in/#=/label workflow scales cleanly to more variables without any change in technique.