The Gryffindor table
The following picture shows who is sitting at the Gryffindor
table. Define the functor sits_right_of/2
to
represent who is sitting right of
whom. sits_right_of(X,Y)
should be true if
X
is to the right of Y.
Based on this knowledge base, formulate the rules defining the following predicates:
-
sits_left_of/2
:sits_left_of(X,Y)
should be true ifX
is to the left ofY
.
Hint -
are_neighbors_of/3
:are_neighbors_of(X,Y,Z)
should be true ifX
is to the left ofZ
andY
is to the right ofZ
.
Solution -
next_to_each_other/2
:next_to_each_other(X,Y)
should be true ifX
is next toY
.
Hint
Test your implementation by asking queries. For example:
- Is Lavender to the right of Parvati?
- Is Lavender to the right of Neville?
- Who is to the right of Hermione?
- Who is sitting at the table?
- Who is sitting two seats to the right of Hermione?
- Who is sitting between Neville and Fred?