1. The Brown Basket is 4 baskets away from the Purple Basket. (i.e., there
are exactly 3 baskets in between Brown and Purple)
(brown色的篮子和purple色的篮子中间有三个篮子)
2. Either the Blue Basket or the Orange basket lies between the Green and
Yellow Baskets.
(不是blue色的篮子在green篮子和yellow篮子的中间,就是organe篮子在他们中间)
3. The Blue Basket is not next to the Orange basket
(blue篮子和orange篮子不挨着)
4. The Brown and Red Baskets are next to each other.
(brown篮子和red篮子是挨着的)
5. The Orange basket is somewhere to the right of the Brown Basket.
(orange篮子在brown篮子的右边)
6. The Red basket is the first basket on the left.
(red篮子是第一个篮子)
我写了一段prolog程序想去得到整个颜色篮子的排列顺序,我是初学,不知道我写的为什么是错的,得不到正确结果,请大家帮我看下。
% 定义一个函数,说明一个物体在另一个物体的右边
iright(L, R, [L | [R | _]]).
iright(L, R, [_ | Rest]) :- iright(L, R, Rest).
%定义两个物体在一起的函数
nextto(L, R, List) :- iright(L, R, List).
nextto(L, R, List) :- iright(R, L, List).
%定义函数说明X在L和R的中间
inbetween(X,L,R,LS):- iright(L,X,LS), iright(X,R,LS).
inbetween1(X,Y,L,R,LS1):- \+inbetween(X,L,R,LS1),inbetween(Y,L,R,LS1),Y\=X.
inbetween1(X,Y,L,R,LS1):- \+inbetween(Y,L,R,LS1),inbetween(X,L,R,LS1),Y\=X.
%定义说明L和R中间只有三个篮子。
threebetween(L,R,LST):- iright(L,X,LST),iright(X,Y,LST),iright(Y,Z,LST),iright(Z,R,LST).
threebetween(L,R,LST):- iright(R,X,LST),iright(X,Y,LST),iright(Y,Z,LST),iright(Z,L,LST).
%定义说明两个物体不挨着
apartfromeachother(L,R,NLST):- \+nextto(L,R,NLST).
%这是facts
myprogram(Data) :- =(Data, [red,_,_,_,_,_,_]),
member(brown,Data),
member(purple,Data),
member(blue,Data),
member(yellow,Data),
member(green,Data),
member(orange,Data),
member(red,Data),
threebetween(brown,purple,Data),
inbetween(blue,orange,green,yellow,Data),
apartfromeachother(blue,orange,Data),
nextto(brown,red,Data),
iright(brown,orange,Data).
事实是结果是正确的,但是有个函数一直没有纠正,就是最后一个说orange颜色的在brown的右边,我的函数写的是紧跟在右边,但是要求说的是只要在右边就可以,但是我不知道怎么去改这个问题,大家给我点意见,谢谢。
1 个解决方案
#1
大家帮帮忙看下啊
#1
大家帮帮忙看下啊