rendered paste body/* Dinner party prolog file */
table([seat(0,_),seat(1,_),seat(2,_),seat(3,_),seat(4,_),seat(5,_),seat(6,_), seat(7,_)]).
dinner(Table) :- table(Table),
member(seat(0, mrsDavis), Table),
member(seat(SeatMRDAVIS, mrDavis), Table),
member(seat(SeatMRBLAKE, mrBlake), Table),
member(seat(SeatMRSBLAKE, mrsBlake), Table),
member(seat(SeatMRASTOR, mrAstor), Table),
member(seat(SeatMRSASTOR, mrsAstor), Table),
member(seat(SeatMRCRANE, mrCrane), Table),
member(seat(SeatMRSCRANE, mrsCrane), Table),
member(seat(1, LDavis), Table),
member(seat(7, RDavis), Table),
leftPerson(SeatMRSASTOR,SeatMRBLAKE),
accrossFrom(SeatMRSCRANE, SeatMRBLAKE),
seatCounter(P,SeatMRDAVIS,SeatMRBLAKE,SeatMRASTOR,SeatMRCRANE, N),
married(LDavis, RDavis), N =:= 1.
rightPerson(X,Y) :- Y is ((X+7) mod 8).
leftPerson(X,Y) :- Y is ((X+1) mod 8).
accrossFrom(X,Y) :- X is ((Y+4) mod 8).
seatCounter(P,SeatMRDAVIS,SeatMRBLAKE,SeatMRASTOR,SeatMRCRANE, N) :-
upCount(0,SeatMRDAVIS,SeatMRBLAKE,SeatMRASTOR,SeatMRCRANE, C0),
upCount(1,SeatMRDAVIS,SeatMRBLAKE,SeatMRASTOR,SeatMRCRANE, C1),
upCount(2,SeatMRDAVIS,SeatMRBLAKE,SeatMRASTOR,SeatMRCRANE, C2),
upCount(3,SeatMRDAVIS,SeatMRBLAKE,SeatMRASTOR,SeatMRCRANE, C3),
upCount(4,SeatMRDAVIS,SeatMRBLAKE,SeatMRASTOR,SeatMRCRANE, C4),
upCount(5,SeatMRDAVIS,SeatMRBLAKE,SeatMRASTOR,SeatMRCRANE, C5),
upCount(6,SeatMRDAVIS,SeatMRBLAKE,SeatMRASTOR,SeatMRCRANE, C6),
upCount(7,SeatMRDAVIS,SeatMRBLAKE,SeatMRASTOR,SeatMRCRANE, C7),
N is (C0+C1+C2+C3+C4+C5+C6+C7).
upCount(P,SeatMRDAVIS,SeatMRBLAKE,SeatMRASTOR,SeatMRCRANE, V) :- betweenMen(P,SeatMRDAVIS,SeatMRBLAKE,SeatMRASTOR,SeatMRCRANE), V is 1.
upCount(P,SeatMRDAVIS,SeatMRBLAKE,SeatMRASTOR,SeatMRCRANE, V) :- not(betweenMen(P,SeatMRDAVIS,SeatMRBLAKE,SeatMRASTOR,SeatMRCRANE)), V is 0.
betweenMen(P, MD,MB,MA,MC) :-
isBetween(P, MA, MB);
isBetween(P, MA, MC);
isBetween(P, MA, MD);
isBetween(P, MB, MC);
isBetween(P, MB, MD);
isBetween(P, MC, MD).
isBetween(A,X,Y) :- rightPerson(X,A), leftPerson(Y,A).
isBetween(A,X,Y) :- rightPerson(Y,A), leftPerson(X,A).
%--------------------------------------------------------------------