我有一个与爱因斯坦之谜非常相似的程序,需要在Prolog中解决,我使用了发现的这种解决方案Einstein.pl来帮助我。这是我的提示和问题: 有五个办公室,每个办公室有不同的颜色,工作的人来自不同的领域,有不同的PC,喝着不同的饮料,并且有不同的手机。
提示:
我需要找到哪个人拥有Windows XP笔记本电脑和哪个人喝水。
这是我所做的,我认为它应该可以工作,我看不到任何错误,但是当我运行它时,我遇到了一些错误,并且我不知道为什么,如果有人可以帮助我,那会很好,谢谢。 / p>
right_of(X, Y) :- X is Y+1.
left_of(X, Y) :- right_of(Y, X).
next_to(X, Y) :- right_of(X, Y).
next_to(X, Y) :- left_of(X, Y).
solution(Ps, Pc, Drink) :-
Ps = [ office(1, Color1, Sector1, Pc1, Drink1, Mobile1),
office(2, Color2, Sector2, Pc2, Drink2, Mobile2),
office(3, Color3, Sector3, Pc3, Drink3, Mobile3),
office(4, Color4, Sector4, Pc4, Drink4, Mobile4),
office(5, Color5, Sector5, Pc5, Drink5, Mobile5)],
hint(office(_, _,computers, _, _, red), Ps),
hint(office(_, _, organdman, macpro, _, _), Ps),
hint(office(_, green, _, _, coffee, _), Ps),
hint(office(_, _, economics, _, tea, _), Ps)
hint(office(A, green, _, _, _, _), Ps),
hint(office(B, mpez, _, _, _, _), Ps),
right_of(A,B),
hint(office(_, _, _, macair, _, iphone), Ps),
hint(office(_, yellow, _, _, _, blackberry), Ps),
hint(office(3, _, _, _, milk, _), Ps),
hint(office(1, _, international, _, _, _), Ps),
hint(office(C, _, _, _, _, nokia), Ps),
hint(office(D, _, _, netbook, _, _), Ps),
next_to(C, D),
hint(office(E, _, _, _, _,blackberry), Ps),
hint(office(F, _, _, windows7, _, _), Ps),
next_to(E, F),
hint(office(_, _, _, _, orange, android), Ps),
hint(office(_, _, supply, _, _, ericsson), Ps),
hint(office(G, _, international, _, _, _), Ps),
hint(office(H, blue, _, _, _, _), Ps),
next_to(G, H),
hint(office(Pc, _, _, windowsxp, _, _), Ps),
hint(office(Drink, _, _, _, water, _), Ps).