Javalicious
Javalicious

Reputation: 43

Einstein's riddle

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.

Upvotes: 2

Views: 3405

Answers (1)

jejansse
jejansse

Reputation: 31

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.

Upvotes: 1

Related Questions