colors( []).
colors( [ Country/Color|Rest]) :-
  colors( Rest),
  member( Color,[yellow,blue,red,green]),
  not( (member( Country1/Color,Rest),neighbor( Country,Country1)) ).
     % Note the extra parentheses, to make a single conjunctive goal of two

neighbor( Country,Country1) :-
  ngb( Country,Neighbors),
  member( Country1,Neighbors).

makelist( List) :-
  collect( [germany],[],List).

collect( [],Closed,Closed).  % No more candidates for closed
collect( [ X|Open],Closed,List) :-
  member( X,Closed),!,	       % If X has already been collected,
  collect( Open,Closed,List).  % discard it
collect( [X|Open],Closed,List) :-
  ngb( X,Ngbs),
  append( Ngbs,Open,Open1),  % built-in version of concat
  collect( Open1,[ X|Closed],List).

country( X) :- ngb( X,_).  % Incomplete ngb relation below gives only six countries

% Neighbors for the 6 original EU countries (Treaty of Rome, 1957)
% Andorra, Monaco, San Marino, and Vatican City are not considered
% Only land (bridge and tunnel included) borders are considered
ngb( germany, [denmark,poland,czech,austria,switzerland,france,luxembourg,belgium,netherlands]).
ngb( netherlands, [germany,belgium,france]).
ngb( belgium, [netherlands,germany,luxembourg,france]).
ngb( france, [belgium,luxembourg,germany,switzerland,italy,spain]).
ngb( luxembourg, [belgium,germany,france]).
ngb( italy, [france,austria,slovenia]).

ngb( denmark, [germany]).
ngb( poland, [germany]).
ngb( czech, [germany]).
ngb( austria, [germany, italy]).
ngb( switzerland, [germany,italy,france]).
ngb( spain, [france]).
ngb( slovenia, [italy]).

