Toggle navigation
?
users online
Logout
Open hangout
Open chat for current file
/** <examples> ?- seating(S). */ seating(Friends) :- % % 8 friends are sitting at a round table. % % Their names are Alice, Bruce, Claire, David, Eugene, Franny, Greta, and Henry. % in any order (permutation) permutation([alice,bruce,claire,david,eugene,franny,greta,henry], Friends), opposite(alice, david, Friends), % Alice is sitting directly opposite of David inbetween(greta, henry, eugene, Friends), % Henry is sitting between Greta and Eugene. inbetween(greta, _, claire, Friends), % There is one person between Greta and Claire. leftof(eugene, david, Friends), % Eugene is sitting immediately to David's left. \+ next(franny, alice, Friends), % Franny is not next to Alice or David. \+ next(franny, david, Friends). % do X and Y sit opposite each other in the circle of Friends? opposite(X, Y, Friends) :- Friends = [X, _, _, _, Y, _, _, _]. opposite(X, Y, Friends) :- Friends = [_, X, _, _, _, Y, _, _]. opposite(X, Y, Friends) :- Friends = [_, _, X, _, _, _, Y, _]. opposite(X, Y, Friends) :- Friends = [_, _, _, X, _, _, _, Y]. opposite(X, Y, Friends) :- Friends = [Y, _, _, _, X, _, _, _]. opposite(X, Y, Friends) :- Friends = [_, Y, _, _, _, X, _, _]. opposite(X, Y, Friends) :- Friends = [_, _, Y, _, _, _, X, _]. opposite(X, Y, Friends) :- Friends = [_, _, _, Y, _, _, _, X]. % does M sit in between L and R in the circle of Friends? inbetween(L, M, R, Friends) :- leftof(L, M, Friends), leftof(M, R, Friends). inbetween(L, M, R, Friends) :- leftof(R, M, Friends), leftof(M, L, Friends). % do X and Y sit next to each other in the circle of Friends? next(X, Y, Friends) :- leftof(X, Y, Friends). next(X, Y, Friends) :- leftof(Y, X, Friends). % does X sit to the left of Y in the circle of Friends? leftof(X, Y, Friends) :- nextto(X, Y, Friends). leftof(X, Y, Friends) :- Friends = [Y|_], last(Friends, X). % nextto and last are built-in. [Y|_] means Y is the first in the list.