Example: using "Generate & Test" pattern
Constraints: 5 countries: A, B, C, D, E; 3 colours: red, blue, white
/* define the colours */
colour(red).
colour(blue).
colour(white).
/* solve; first Generate (values) */
solve( [ A, B, C, D, E ] ) :- colour(A), colour(B), colour(C),
colour(D), colour(E),
colour(D), colour(E),
/* then Test (constraints) */
not A = B, not A = C, not A = E, not A = D,
not B = C, not C = D, not E = D.
Note that this uses the simple Generate and Test approach which is highly inefficient. Prolog will generate all the values for A through E first, before testing any constraints. Prolog will assign all the same values the first time, then change the last variable through all combinations of possible values, before moving to the second last variable, etc. This results in many 'fails', which means a lot of back-tracking, and thus very slow to find any solution, if one exists. For best performance, interleave Tests with Generated values. Must always generate values though, even if they are known