General
Material
Lecture 1
Lecture 2
Lecture 3
Lecture 4
Lecture 5

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.

Solution

Based on this knowledge base, formulate the rules defining the following predicates:

  • sits_left_of/2: sits_left_of(X,Y) should be true if X is to the left of Y.
    Hint
  • are_neighbors_of/3: are_neighbors_of(X,Y,Z) should be true if X is to the left of Z and Y is to the right of Z.
    Solution
  • next_to_each_other/2: next_to_each_other(X,Y) should be true if X is next to Y.
    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?

Back to the practical session of day 1.