%% file: map.pl %% author: Robert Keller %% purpose: coloring a map using Prolog map([A,B,C,D,E,F,G], Colors) :- next(A,B, Colors), next(A,C, Colors), next(A,D, Colors), next(A,E, Colors), next(B,D, Colors), next(B,F, Colors), next(C,D, Colors), next(C,E, Colors), next(C,F, Colors), next(D,F, Colors), next(E,F, Colors), next(E,G, Colors), next(F,G, Colors). next(X, Y, Colors) :- %% two adjacent regions are colored differently member(X, Colors), member(Y, Colors), X \== Y. test2 :- map(Solution, [red, blue]), write(Solution). test3 :- map(Solution, [red, blue, green]), write(Solution).