2

I am new to Prolog and I'm trying to model a riddle like the Einstein riddle, also known as the Zebra riddle, (but with 10 houses and 30 hints) in Prolog and I'm using this model example as a starting point:

http://www.baptiste-wicht.com/2010/09/solve-einsteins-riddle-using-prolog/

But in my riddle, i have to be able to say that X is right of Y. And I don't mean directly right, but right of in the list. So Y can be in house 1, while X in house 9.

How can I do this in Prolog? I was thinking about a predicate which says that Y is a member of the list constructed by taking X and all elements before X out of that list, but I'm not sure how to do that or make that so that I can fit it in the before mentioned example.

1 Answer 1

1

right(X,Y) :- right(X,Z),right(Z,Y).

Hence, you just use a transitive closure to define the right predicate and then define the elements that are directly next to each other.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.