Prolog Logic 与相邻的房间
Prolog Logic with adjacent rooms
这是我的问题:
Hunter, Laura, Addiley (jack), Ramey(Sally), and Arnie(Jim) all live
in the same dorm with five adjacent bedrooms. Hunter doesn’t sleep in
the 5th bedroom and Laura doesn’t sleep in the first bedroom. Arnie
doesn’t sleep in the first or last bedroom, and he is not in an
bedroom adjacent to Addiley or Laura. Ramey sleeps in some bedroom
higher than Laura’s. Who sleeps in which bedrooms? Write a Prolog
program to solve this problem.
Define what adjacency is, then what the bedrooms are, and then create
a layout(X)
that allows you to put in all the rules.
这是我目前的代码,我也尝试了一些变体:
adjcnt(X,Y) :- X = (Y+1;Y-1).
rooms([ bedroom(_, 1), bedroom(_, 2), bedroom(_, 3), bedroom(_, 4), bedroom(_, 5) ]).
layout(X) :- rooms(X),
member( bedroom(hunter, V), X),
member( bedroom(laura, W), X),
member( bedroom(arnie, X), X),
member( bedroom(ramey, Y), X),
member( bedroom(addiley,Z), X),
V \= 5,
W \= 1,
X \= 1,
X \= 5,
X \= adjcnt(X,Z),
X \= adjcnt(X,W),
Y @> W.
主要问题是,我对相邻房间的计算是否正确?以及如何正确实施。当我尝试 运行 代码时,我不断收到 "NO"。感谢任何能帮助我的人!!
这是我的问题:
Hunter, Laura, Addiley (jack), Ramey(Sally), and Arnie(Jim) all live in the same dorm with five adjacent bedrooms. Hunter doesn’t sleep in the 5th bedroom and Laura doesn’t sleep in the first bedroom. Arnie doesn’t sleep in the first or last bedroom, and he is not in an bedroom adjacent to Addiley or Laura. Ramey sleeps in some bedroom higher than Laura’s. Who sleeps in which bedrooms? Write a Prolog program to solve this problem.
Define what adjacency is, then what the bedrooms are, and then create a
layout(X)
that allows you to put in all the rules.
这是我目前的代码,我也尝试了一些变体:
adjcnt(X,Y) :- X = (Y+1;Y-1).
rooms([ bedroom(_, 1), bedroom(_, 2), bedroom(_, 3), bedroom(_, 4), bedroom(_, 5) ]).
layout(X) :- rooms(X),
member( bedroom(hunter, V), X),
member( bedroom(laura, W), X),
member( bedroom(arnie, X), X),
member( bedroom(ramey, Y), X),
member( bedroom(addiley,Z), X),
V \= 5,
W \= 1,
X \= 1,
X \= 5,
X \= adjcnt(X,Z),
X \= adjcnt(X,W),
Y @> W.
主要问题是,我对相邻房间的计算是否正确?以及如何正确实施。当我尝试 运行 代码时,我不断收到 "NO"。感谢任何能帮助我的人!!