2
我目前正在嘗試學習一點Prolog。作爲一個練習我試圖解決以下幾個謎語:序言 - 試圖解決文本謎題
這些規則給出:
*Every person that has neither a car nor a plane, has a bike.
*Every person that doesn't have a plane but has a bike, has a car
*Every person that doesn't have a plane but has a car, has a truck
*Every person that doesn't have a truck but has a boat, doesn't have a plane
*Every person that doesn't have a boat but has a plane, doesn't have a car
現在有四個人:
*Person1 doesn't have a car but has a boat
*Person2 doesn't have a boat but has a plane
*Person3 doesn't have a plane but has a bike
*Person4 doesn't have a bike but has a car
哪個人沒有一輛卡車?
我想出來的,到目前爲止是這樣的:
doesnthave(car,pa).
has(boat,pa).
doesnthave(boat,pb).
has(plane,pb).
doesnthave(plane,pc).
has(bike,pc).
doesnthave(bike,pd).
has(car,pd).
has(bike,X) :- doesnthave(car,X),doesnthave(plane,X).
has(car,X) :- doesnthave(plane,X),has(bike,X).
has(truck,X) :- doesnthave(plane,X),has(car,X).
doesnthave(plane,X) :- doesnthave(truck,X),has(boat,X).
doesnthave(car,X) :- doesnthave(boat,X),has(plane,X).
現在,這似乎並不足夠。或者這不是在prolog中解決像這樣的難題的方法嗎?
編輯:看起來前兩個陳述是矛盾的。它們一起產生:每個既沒有汽車也沒有飛機的人擁有一輛汽車。我不確定是否有明智的解決方案。
事實證明,前兩個陳述存在矛盾。 他們一起屈服:每個既沒有汽車也沒有飛機的人擁有一輛汽車。 – tschaei