Hi folks, I'm on a beginner level course in prolog, doing a map colouring problem. Here's my code.
col(Colors,Map,Coloring) :-
checkMap(Colors,Map,Coloring).
checkMap(Colors,[Country1:Country2],Coloring) :-
goodColor(Country1:Country2,Coloring,Colors).
checkMap(Colors,[Country1:Country2|Rest],Coloring) :-
goodColor(Country1:Country2,Coloring,Colors),
checkMap(Colors,Rest,Coloring).
goodColor(Country1:Country2,Coloring,Colors) :-
mem(Country1:Color1,Coloring),!,
mem(Country2:Color2,Coloring),!,
mem(Color1,Colors), mem(Color2,Colors),
not(Color1=Color2).
mem(Var,[Var|_]).
mem(Var,[_|Rest]) :-
mem(Var,Rest).
My output looks like this:
?- col([a,b,c],[1:2,1:3,2:3],X).
X = [1:a, 2:b, 3:c|_G332] ;
X = [1:a, 2:c, 3:b|_G332] ;
X = [1:b, 2:a, 3:c|_G332] ;
X = [1:b, 2:c, 3:a|_G332] ;
X = [1:c, 2:a, 3:b|_G332] ;
X = [1:c, 2:b, 3:a|_G332] ;
fail.
Anyone know how I can get rid of the trailing variable? I know it's mostly cosmetic, but I don't see why it's there.