【发布时间】:2013-11-24 15:45:09
【问题描述】:
我是一个完全的编程初学者,必须使用 GNU Prolog 在 Prolog 中创建和解决一个谜题,类似于爱因斯坦谜题,尽管不太复杂。我一直在尝试为以下table 中包含的项目创建一个谜语。
到目前为止,我的代码看起来像这样,但我真的不完全理解我在做什么错或正确。我可以在 GNU Prolog 中编译代码,但它无法解开谜团:
middle(M,[_,M,_]).
right(A,B,[[_|A]|B]).
left(A,B,[A|[B|_]]).
run:-
X = [_,_,_],
middle([_,brown,_],X), /* the brown guinea pig lives in the middle of the cage */
member([brown,carrots,_],X), /* the brown guinea pig loves to eat carrots */
member([_,salad,giggles],X), /* the salad eating guinea pig giggles */
right([_,salad,_],[brown,_,_],X), /* the salad eating guinea pig sits to the right of the brown guinea pig */
left([black,_,_],[_,_,squeaks],X), /* the black guinea pig sleeps to the left of the squeaking guinea pig */
member([black,_,grumbles],X), /* the black guinea pig grumbles */
member([grey,_,giggles],X), /* the grey guinea pig giggles*/
write(X),nl, /* write out all fur colors */
write('the '),write(N),write(' guinea pig loves to eat cucumbers'),nl. /* answer to the question */
我非常感谢任何帮助,因为我对这些东西很陌生,但必须为我正在上课的课程找出解决方案。任何提示都会有很大帮助。谢谢!
【问题讨论】:
-
请将您的代码粘贴到 SO。请阅读stackoverflow.com/help!
-
类似问题请见these solutions。
标签: prolog logic zebra-puzzle