天步版主你好
想請問一下,上次你幫我解的五個村莊問題
是如何解出來的,如果要解釋解出來的步驟該如何講
我友點不明瞭,能否指點一下
另外有一題prolgo的程式怪怪的
我明明已經沒出現錯誤訊息
但是位何執行時會出現錯誤訊息呢?
能否幫我看一下
謝謝
原始程式碼
ngb(italy,[switzerland,france,austria,slovenia,monaco,vatican]).
ngb(vatican,[italy]).
ngb(monaco,[france,italy]).
ngb(france,[monaco,italy,switzerland,liechtenstein,germany,luxembourg,belgium,netherland,spain]).
ngb(luxembourg,[france,germany,belgium]).
ngb(belgium,[france,luxembourg,germany,netherland]).
ngb(netherland,[france,belgium,germany]).
ngb(spain,[france,portugal]).
ngb(portugal,[spain]).
ngb(britain,[ireland]).
ngb(ireland,[britain]).
ngb(iceland,[]).
ngb(malta,[]).
colours([]).
colours([Country/Colour|Rest]):-
colours(Rest),member(******,[yellow,blue,red,green]),not((member(Country1/*****,Rest),neighbour(Country,Country1))).
neighbour(County,Country1):-ngb(******,Neighbours),member(******,Neighbours).
makelist(L):-collect([germany],[],L).
collect([],Closed,Closed).
collect([X|Open],Closed,L):-member(X,Closed),!,collect(Open,Closed,L).
collect([X|Open],Closed,L):-ngb(X,Ns),append(Ns,Open,Op1),collect(Op1,[X|Closed],L).
country(C):-ngb(C,_).
打*是要寫入的部份
解出來的程式碼
ngb(italy,[switzerland,france,austria,slovenia,monaco,vatican]).
ngb(vatican,[italy]).
ngb(monaco,[france,italy]).
ngb(france,[monaco,italy,switzerland,liechtenstein,germany,luxembourg,belgium,netherland,spain]).
ngb(luxembourg,[france,germany,belgium]).
ngb(belgium,[france,luxembourg,germany,netherland]).
ngb(netherland,[france,belgium,germany]).
ngb(spain,[france,portugal]).
ngb(portugal,[spain]).
ngb(britain,[ireland]).
ngb(ireland,[britain]).
ngb(iceland,[]).
ngb(malta,[]).
colours([]).
colours([Country/colours|Rest]):-
colours(Rest),member(X,Closed,[yellow,blue,red,green]),not((member(Country1/X,Closed,Rest),neighbour(Country,Country1))).
neighbour(Country,Country):-ngb(X,Neighbours),member(X,colour,Neighbours).
makelist(L):-collect([germany],[],L).
collect([],Closed,Closed).
collect([X|Open],Closed,L):-member(X,Closed),!,collect(Open,Closed,L).
collect([X|Open],Closed,L):-ngb(X,Ns),append(Ns,Open,Op1),collect(Op1,[X|Closed],L).
country(C):-ngb(C,_).
求解打 setof(Cntry/Colour,country(Cntry),CountryColourList),colours(CountryColourList).
執行後會出現的訊息
?- setof(Cntry/Colour,country(Cntry),CountryColourList),colours(CountryColourList).
ERROR: Undefined procedure: member/3
ERROR: However, there are definitions for:
ERROR: member/2
ERROR: member/2
?-
為何會這樣呢?
能否幫我看一下