houses([
	house(first, _, _, _, _, _),
	house(second, _, _, _, _, _),
	house(third, _, _, _, _, _),
	house(forth, _, _, _, _, _),
	house(fifth, _, _, _, _, _)
]).

right_of(A, B, [B, A | _]).
right_of(A, B, [_ | Y]) :- right_of(A, B, Y).

next_to(A, B, [A, B | _]).
next_to(A, B, [B, A | _]).
next_to(A, B, [_ | Y]) :- next_to(A, B, Y).

mymember(X, [X|_]).
mymember(X, [_|Y]) :- mymember(X, Y).

print_houses([]).
print_houses([A|B]) :-
	write(A), nl,
	print_houses(B).


where_fish(H):-houses(H),
               mymember(house(_,red,english,_,_,_),H),
               mymember(house(_,_,swedish,dog,_,_),H),
               mymember(house(_,_,datman,_,tea,_),H),
               right_of(house(_,green,_,_,_,_),
                        house(_,white,_,_,_,_),H),
               mymember(house(_,green,_,_,coffe,_),H),
               mymember(house(_,_,_,bird,_,pallmall),H),
               H=[_,_,house(_,_,_,_,milk,_),_,_],
               mymember(house(_,yellow,_,_,_,dunhill),H),
               mymember(house(first,_,norway,_,_,_),H),
               next_to(house(_,_,_,_,_,marlboro),
                       house(_,_,_,cat,_,_),H),
               next_to(house(_,_,_,horse,_,_),
                       house(_,_,_,_,_,dunhill),H),
               mymember(house(_,_,_,_,bear,winfield),H),
               next_to(house(_,_,norway,_,_,_),
                       house(_,blue,_,_,_,_),H),
               mymember(house(_,_,denmark,_,_,rothmans),H),
               next_to(house(_,_,_,_,_,marlboro),
                       house(_,_,_,_,water,_),H),
               print_houses(H).

:-where_fish(_).