【问题标题】:error in Prolog code - undefined procedure: unique/1Prolog 代码中的错误 - 未定义的过程:唯一/1
【发布时间】:2014-11-26 21:51:47
【问题描述】:

%三个动作变体。我有 3 只动物,它可以驾驶飞机、汽车或错过 %step。我知道,第一步猴子坐飞机,狼坐汽车。在第二个 %step 狼乘坐飞机。我们需要知道剩余的一致性。并且每只动物只准时乘坐%每辆车

action(plane).
action(car).
action(shift).

%我在我的函数解决方案中声明乘客

solve([passenger(monkey, [X1,X2,X3]), passenger(wolf, [Y1, Y2,Y3]),
passenger(hippo, [Z1, Z2, Z3])]):-
   action(X1), action(Y1), action(Z1), unique([X1, Y1, Z1]),
   action(X2), action(Y2), action(Z2), unique([X2, Y2, Z2]),
   action(X3), action(Y3), action(Z3), unique([X3, Y3, Z3]),

   unique([X1, X2, X3]), unique([Y1, Y2, Y3]), unique([Z1, Z2, Z3]),

   X1 = plane, Y1 = car,
   Y2 = plane.

【问题讨论】:

  • Undefined procedure unique/1 表示您没有在任何地方使用一个参数定义 unique 谓词。

标签: prolog zebra-puzzle


【解决方案1】:

可能unique/1 完全不同:

unique([]).
unique([E|Es]) :-
   maplist(dif(E), Es),
   unique(Es).

【讨论】:

  • 我该怎么办?
  • @Zakhar:将上述内容包含到您的程序中。最好在action/1 事实之前
猜你喜欢
  • 1970-01-01
  • 2015-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-22
相关资源
最近更新 更多