map('Australia', [wa: [nt,sa], nt: [wa,sa,qld], qld:[nt,sa,nsw], nsw: [qld,sa,vic], vic: [sa,nsw], tas:[], sa: [wa,nt,qld,nsw,vic]]). map('West Europe', [portugal: [spain], spain: [portugal, france], belgium: [france, holland, luxembrg, germany], holland: [belgium, germany], luxembrg: [france, belgium, germany], switzerld: [france,germany,austria, italy], italy: [france,switzerld, austria], austria: [germany, switzerld, italy], france: [spain,belgium,luxembrg, germany,switzerld, italy], germany:[holland,belgium,luxembrg,france,switzerld, austria]]). colors([red,green,blue,purple]).
| ?- paint('West Europe', X). X = [germany:red,france:red,austria:red,italy:red,switzerld:red,luxembrg:red, holland:red,belgium:red,spain:red,portugal:red] ? X = [germany:green,france:red,austria:red,italy:red,switzerld:red,luxembrg:red, holland:red,belgium:red,spain:red,portugal:red] ? X = [germany:blue,france:red,austria:red,italy:red,switzerld:red,luxembrg:red, holland:red,belgium:red,spain:red,portugal:red] ? etc.
If the first parameter in member(X,List) is left as a variable - you know the List, but not the X - this will generate the members of the list individually: colors([red,green,blue,purple]). getcolor(X) :- colors(List), member(X,List). /* | ?- getcolor(X). X = red ? ; X = green ? ; X = blue ? ; X = purple ? ; */
findneighbors(X, Map, Who) :- map(Map, Countries), neighbors(X,Countries,Who). /* |?- findneighbors(holland,'West Europe',X). X = [belgium,germany] */
adjacent(X,Y,Map) :- findneighbors(X, Map, Countries), member(Y, Countries). /* | ?- adjacent(holland, germany, 'West Europe'). true ? | ?- adjacent(holland, france, 'West Europe'). no | ?- adjacent(spain, france, 'West Europe'). true ? */
different(C, Nbs, [S1:C1|Rest]) :- not((member(S1,Nbs), C = C1)), different(C, Nbs,Rest). different(_,_,[]). member(X, List) :- List = [H|T], X = H. member(X, List) :- List = [_|T], member(X,T). not(G) :- G, !, fail. not(G).