% find the Zebra and the Water, zebra_water(X).
% by Willem Robert van Hage, wrvhage@science.uva.nl

right(2,1).
right(3,2).
right(4,3).
right(5,4).
nextdoor(X,Y) :- right(X,Y).
nextdoor(X,Y) :- right(Y,X).

match([],_).
match([X|Xs],Ys) :-
        member(X,Ys),
        match(Xs,Ys).

zebra_water(X) :-
        nextdoor(Horse,Diplomat),
        nextdoor(Fox,Doctor),
        nextdoor(Norwegian,Blue),
        Y = [house(    Green,          _,  green,         _,      _,      _),
             house(    White,          _,  white,         _,      _,      _),
             house(Norwegian,  norwegian,      _,         _,      _,      _),
             house(     Blue,          _,   blue,         _,      _,      _),
             house(      Fox,          _,      _,         _,    fox,      _),
             house(   Doctor,          _,      _,    doctor,      _,      _),
             house(    Horse,          _,      _,         _,  horse,      _),
             house( Diplomat,          _,      _,  diplomat,      _,      _),
             house(        3,          _,      _,         _,      _,   milk),
             house(        1,  norwegian,      _,         _,      _,      _),
             house(        _, englishman,    red,         _,      _,      _),
             house(        _,   spaniard,      _,         _,    dog,      _),
             house(        _,   japanese,      _,   painter,      _,      _),
             house(        _,    italian,      _,         _,      _,    tea),
             house(        _,          _, yellow,  diplomat,      _,      _),
             house(        _,          _,  green,         _,      _, coffee),
             house(        _,          _,      _,  sculptor, snails,      _),
             house(        _,          _,      _, violinist,      _,  juice),
             house(        _,          _,      _,         _,  zebra,      _),
             house(        _,          _,      _,         _,      _,  water) ],
        X = [ house(1,_,_,_,_,_),
              house(2,_,_,_,_,_),
              house(3,_,_,_,_,_),
              house(4,_,_,_,_,_),
              house(5,_,_,_,_,_) ],
        right(Green,White),
        match(Y,X).