I am trying to solve Einstein Riddle in Prolog.
I am having a difficulty with the program I wrote, the basic method was to add all constraints and let Prolog figure out the only possible solutions.
The problem is that Prolog finds 0 solutions. I have isolated the constraint that makes the program go from a given solution to no solutions, but I don't understand why.
/*There are five houses*/
exists(A, list(A,_,_,_,_)).
exists(A, list(_,A,_,_,_)).
exists(A, list(_,_,A,_,_)).
exists(A, list(_,_,_,A,_)).
exists(A, list(_,_,_,_,A)).
middle_house(A, list(_,_,A,_,_)).
first_house(A, list(A,_,_,_,_)).
nextTo(A, B, list(B,A,_,_,_)).
nextTo(A, B, list(_,B,A,_,_)).
nextTo(A, B, list(_,_,B,A,_)).
nextTo(A, B, list(_,_,_,B,A)).
nextTo(A, B, list(A,B,_,_,_)).
nextTo(A, B, list(_,A,B,_,_)).
nextTo(A, B, list(_,_,A,B,_)).
nextTo(A, B, list(_,_,_,A,B)).
/* each statement will be described using the clues
house conatins: Color,Owner, Drinks, Smokes, Pet*/
riddle(Houses):-
/*exists(house(red, englishman, _,_,_),Houses),*/
nextTo(house(_,norwegian,_,_,_), house(blue,_,_,_,_), Houses),
exists(house(_,spanish,_,_, dog), Houses),
exists(house(green, _, coffee, _,_), Houses),
exists(house(_, ukrain, tea,_,_), Houses),
nextTo(house(white,_,_,_,_), house(green,_,_,_,_), Houses),
exists(house(_,_,_,marlbero, cat),Houses),
exists(house(yellow,_,_,time,_), Houses),
middle_house(house(_,_,milk,_,_), Houses),
first_house(house(_,norwegian,_,_,_), Houses),
nextTo(house(_,_,_,_,fox), house(_,_,_,montena,_), Houses),
nextTo(house(_,_,_,time,_), house(_,_,_,_,horse), Houses),
exists(house(_,_,orange,lucky,_), Houses),
exists(house(_,japanese,parlament,_), Houses).
The current solution to this is this:
?- riddle(Houses). Houses = list( house(green, norwegian, coffee, marlbero, cat), house(white, spanish, orange, lucky, dog), house(yellow, norwegian, milk, time, fox), house(blue, ukrain, tea, montena, horse), house(_G7257, japanese, parlament, _G7260)).
and if I uncomment the first line then that same statement returns false.
I would like help understanding why this is the case. I noted that in the partial solution the Norwegian appears twice and that this might indicate the problem.
nextTo(house(white,_,_,_,_), house(green,_,_,_,_), Houses)
isn't restrictive enough. According to the original puzzle, the green house is right of the white house, not just next to. – lurkerriddle/1
predicate) is missing onehouse
argument:exists(house(_,japanese,parlament,_), Houses)
. It should beexists(house(_,japanese,_,parlament,_), Houses)
. – lurker