I am trying to create a program in which the predicate seating(Diners, Positions) holds if the people in the list Diners can be re-arranged into the list Positions so that each diner is compatible to the diners on either side. There are 8 diners in total seated around a circular table. Each diner speaks several languages and must be able to speak to the two diners either side.
I have defined a predicate is_common which is a rule that tests if two diners have a common language.
common([],_,[]).
common([A|As],Language,[A|Bs]) :- member(A,Language), !, common(As,Language,Bs).
common([_|As],Language,Bs) :- common(As,Language,Bs).
is_common(G1,G2,L) :- languages(G1,L1), languages(G2,L2), common(L1,L2,X), member(L,X).
I have defined the predicate seating below:
seating(Diners, [P1|Postions]):- select(P1, Diners, NDiners), seats1(P1, NDiners, Positions).
seats1(_, [], []).
seats1(LP, Diners, [RP|Positions]):- select(RP, Diners, NDiners), is_common(LP, RP, _), seats1(R, NDiners, Positions).
I am now trying to create a predicate called seating_plan in order to combine the predicate seating with a final check to make sure that the first and last person in the list are compatible. How would I go about doing this?
