I've started learning Prolog recently and came across a problem.
Some people sit around a table. We are given the fact sits_right_of(X, Y)
(X sits right of Y). Then I wrote the next rules:
sits_left_of(X, Y) :- sits_right_of(Y, X)
(X sits left of Y);are_neighbors_of(X, Y, Z) :- sits_left_of(X, Z)
(X sits left to Z and Y sits right to Z);next_to_each_other(X, Y) :- are_neighbors_of(_, X, Y); are_neighbors_of(X, _, Y)
(X sits next to Y).
How can I find out who is the person who sits two places right (or left) to a given person? Is there some kind of recursive query like sits_right_of(sits_right_of(X, alex))
? Do I need to write another rule for finding out who sits n
places away from somebody?