解决爱因斯坦在Prolog中的谜语类似的问题

时间:2020-01-08 19:34:25

标签: prolog zebra-puzzle

我有一个与爱因斯坦之谜非常相似的程序,需要在Prolog中解决,我使用了发现的这种解决方案Einstein.pl来帮助我。这是我的提示和问题: 有五个办公室,每个办公室有不同的颜色,工作的人来自不同的领域,有不同的PC,喝着不同的饮料,并且有不同的手机。

提示:

  1. 计算机部门设有红色办公室。
  2. 组织和管理部门有macbook pro。
  3. 绿色办公室喝咖啡。
  4. 经济部门喝咖啡。
  5. 绿色办公室紧挨着米色办公室。(米色在我的程序中是mpez)
  6. 装有iphone的人有Macbook air。
  7. 有黑莓手机的人是黄色的办公室。
  8. 中间的办公室喝牛奶。
  9. 第一个办公室来自国际部门。
  10. 有诺基亚的家伙紧挨着上网本的家伙。
  11. 使用黑莓的家伙紧挨着装有Windows 7的家伙。
  12. 有Android的人喝橙汁。
  13. 供应部门的人有爱立信。
  14. 来自国际部门的家伙在蓝色办公室旁边。

我需要找到哪个人拥有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).

Here are the errors i get

0 个答案:

没有答案