43831

# Einstein Riddle using Prolog

I'm trying to solve the Einstein riddle using Prolog. When I'm trying to run by houses(Hs), it shows No. Task is

<ol> <li>The Brit lives in the red house. </li> <li>The Swede keeps dogs as pets. </li> <li>The Dane drinks tea.</li> <li>The green house is on the immediate left of the white house. </li> <li>The green house's owner drinks coffee. </li> <li>The owner who smokes Pall Mall rears birds. </li> <li>The owner of the yellow house smokes Dunhill. </li> <li>The owner living in the center house drinks milk. </li> <li>The Norwegian lives in the first house. </li> <li>The owner who smokes Blends lives next to the one who keeps cats. </li> <li>The owner who keeps the horse lives next to the one who smokes Dunhill.</li> <li>The owner who smokes Bluemasters drinks beer. </li> <li>The German smokes Prince. </li> <li>The Norwegian lives next to the blue house. </li> <li>The owner who smokes Blends lives next to the one who drinks water.</li> </ol>
```    houses(Hs) :-
length(Hs, 5),
member(h(english,_,_,_,red), Hs),
member(h(swede,dog,_,_,_), Hs),
member(h(_,_,_,coffee,green), Hs),
member(h(dane,_,_,tea,_), Hs),
next(h(_,_,_,_,green), h(_,_,_,_,white), Hs),
member(h(_,bird,'Pall Mall',_,_), Hs),
member(h(_,_,'Dunhill',_,yellow), Hs),
Hs = [_,_,h(_,_,_,milk,_),_,_],
Hs = [h(norwegian,_,_,_,_)|_],
next(h(_,horse,_,_,_), h(_,_,'Dunhill',_,_), Hs),
next(h(_,_,blend,_,_), h(_,cat,_,_,_), Hs),
member(h(_,_,'Blue Master',beer,_), Hs),
member(h(german,_,'Prince',_,_), Hs),
next(h(norwegian,_,_,_,_), h(_,_,_,_,blue), Hs),
next(h(_,_,'Blend',_,_), h(_,_,_,water,_), Hs),
member(h(_,fish,_,_,_), Hs).

next(A, B, Ls) :- append(_, [A,B|_], Ls).
next(A, B, Ls) :- append(_, [B,A|_], Ls).
</pre>

I have no idea what is wrong. Thanks
Here is a <strong>generalization</strong> of your program. I added some extra `*` to remove several goals and replaced some terms by `_/*origterm*/`.  And yet, the resulting program is still failing. Therefore, the error <strong>has to be</strong> in the remaining fragment. You did not say anything about the program (Edit: you added something later), so I do not (Edit: want to) know what it is about. But no matter what, the error has to be in the remaining visible part:

:- initialization(houses(_Sol)).
:- op(950, fy, *).
*_.

houses(Hs) :-
length(Hs, 5),
* <s>member(h(english,_,_,_,red), Hs)</s>,                         %  2
* <s>member(h(swede,dog,_,_,_), Hs)</s>,
* <s>member(h(_,_,_,coffee,green), Hs)</s>,
* <s>member(h(dane,_,_,tea,_), Hs)</s>,
* <s>next(h(_,_,_,_,green), h(_,_,_,_,white), Hs)</s>,
member(h(_,_<s>/*bird*/</s>,'Pall Mall',_,_), Hs),
member(h(_,_,'Dunhill',_,_<s>/*yellow*/</s>), Hs),
* <s>Hs = [_,_,h(_,_,_,milk,_),_,_]</s>,
* <s>Hs = [h(norwegian,_,_,_,_)|_]</s>,
* <s>next(h(_,horse,_,_,_), h(_,_,'Dunhill',_,_), Hs)</s>,
next(h(_,_,blend,_,_), _<s>/*h(_,cat,_,_,_)*/</s>, Hs),
member(h(_,_,'Blue Master',_<s>/*beer*/</s>,_), Hs),
member(h(_<s>/*german*/</s>,_,'Prince',_,_), Hs),
* <s>next(h(norwegian,_,_,_,_), h(_,_,_,_,blue), Hs)</s>,
next(h(_,_,'Blend',_,_), _<s>/*h(_,_,_,water,_)*/</s>, Hs),
* <s>member(h(_,fish,_,_,_), Hs)</s>.

next(A, B, Ls) :- append(_, [A,B|_], Ls).
next(A, B, Ls) :- append(_, [B,A|_], Ls).
</pre>

There is not much left! In the visible part there is at least one error! (And, strictly speaking there may be many more errors in the other parts. We simply don't know).

```