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