I have a Zebra Problem modified but I can't do correct. This are my sentences :
- The Brazilian doesn’t live in the second house.
- The dog owner plays basketball.
- There is an intermediate house between the football players house and the red house.
- The fish owner lives next to the cat owner.
- The dog owner lives next to the green house.
- A German lives in the third house.
This is my attempt but I am getting an error, could someone please help me.
neighborhood(N):-
length(N,3),
member(house(brazilian,_,_),N),
member(house(_,dog,basketball),N),
middle(house(red,_,_),house(_,_,soccer), N),
nextto(house(_,fish,_),house(_,cat,_), N),
nextto(house(_,dog,_),house(green,_,_), N),
N = [_,_,house(german,_,_)].
I think you are quite close; you need:
house(_,_,_,_)
with four slots, you only have three slots, not enough for (Nationality, Pet, Sport, Colour).And you need to be consistent for which thing goes in which place in the house(), your code has
house(brazilian,_,_)
where the first slot is a nationality, andhouse(green,_,_)
where the first slot is a colour.After that the error I get in SWI Prolog is that
middle
does not exist, that needs to be coded; I have made it by writing that there is a variable in the list which is a house, and is next to the soccer house and next to the red house (so, it must be in the middle). There are many other ways you could write it:(It does not seem to need the rule that the brazilian is not in the second house, specifically).