[comp.lang.prolog] The Zebra problem

ferris@eniac.seas.upenn.edu (Richard T. Ferris) (03/14/90)

I am taking a course in decision support systems and one of the
programs we are studying is the "Zebra problem."  This problem
consists of a bunch of facts regarding the persons living in 
five houses next to each other on the same block.  The houses are
identified by their position on the block (left, midleft,middle,
midright, right).  In each house lives a person of a different
nationality who smokes a unique brand of cigarettes, owns a unique
pet, drinks a unique drink, and whose house is a unique color.

The goal is to find out which house owns the zebra.  
I have run the program
sucessfully in C-Prolog but it seems to hang up Turbo Prolog
(version 1.1).  Can anybody tell me why?  I would really appreciate
it.

Richard T. Ferris
ferris@eniac.seas.upenn.edu
University of Pennsylvania

Here is the version modfied to run under Turbo Prolog:
===============================================================
/* begin ZEBRA program */
domains

loc = left;midleft;middle;midright;right

predicates

/*hln is an abbreviation for hasleftneighbor*/
hln(loc,loc)
nextto(loc,loc)
isnot(loc,loc)
rightof(loc,loc)
differ(loc,loc,loc,loc,loc)

clauses

hln(right,midright).
hln(midright,middle).
hln(middle,midleft).
hln(midleft,left).

nextTo(X,Y) :- hln(X,Y).
nextTo(X,Y) :- hln(Y,X).

rightof(X,Y) :- hln(X,Y).
rightof(X,Y) :- hln(X,Z), rightof(Z,Y).

isnot(X,Y) :- rightof(X,Y).
isnot(X,Y) :- rightof(Y,X).

differ(X1,X2,X3,X4,X5) :-
 isnot(X1,X2) , isnot(X1,X3) , isnot(X1,X4) ,
 isnot(X1,X5) , isnot(X2,X3) , isnot(X2,X4) ,
 isnot(X2,X5) , isnot(X3,X4) , isnot(X3,X5) ,
 isnot(X4,X5).


goal

 Englishmen = Redhouse,
 Spaniard = Dogowner,
 Coffeedrinker = Greenhouse,
 Ukranian = Teadrinker, 
 hln(Greenhouse,Ivoryhouse),
 Winstonsmoker = Snailowner,
 Koolsmoker = Yellowhouse,
 Milkdrinker = middle,
 Norwegian = left,
 nextTo(Camelsmoker,Foxowner),
 nextTo(Koolsmoker,Horseowner),
 Luckysmoker = OJdrinker,
 Jap = Parliamentsmoker,
 nextTo(Norwegian,Bluehouse),
 differ(Greenhouse,Yellowhouse,Redhouse,Ivoryhouse,Bluehouse),
 differ(Zebraowner,Foxowner,Horseowner,Snailowner,Dogowner),
 differ(OJdrinker,Milkdrinker,Teadrinker,Coffeedrinker,Waterdrinker),
 differ(Englishman,Spaniard,Norwegian,Jap,Ukranian),
 differ(Koolsmoker,Winstonsmoker,Parliamentsmoker,Luckysmoker,
        Camelsmoker).
       
/* end of ZEBRA program */ 
 
Richard T. Ferris
ferris@eniac.seas.upenn.edu
University of Pennsylvania

jha@lfcs.ed.ac.uk (Jamie Andrews) (03/16/90)

In article <21712@netnews.upenn.edu> ferris@eniac.seas.upenn.edu.UUCP (Richard T. Ferris) writes:
>I have run the program
>sucessfully in C-Prolog but it seems to hang up Turbo Prolog
>(version 1.1).  Can anybody tell me why?  I would really appreciate
>it.

Well, it could be because Turbo runs out of stack space
(the solution space is huge)...  or...

>/* begin ZEBRA program */
> ...
> Englishmen = Redhouse,
> ...
> differ(Englishman,Spaniard,Norwegian,Jap,Ukranian),

... it could be because you spelled "Englishman" differently the
two times you used it... or...

... it could be because Turbo is taking offence at your rather
'40s-style pejorative abbreviation of Japanese...

just some ideas :-)
--Jamie.
  jha@lfcs.ed.ac.uk
Copyright (c) 1990 by Jamie Andrews;
for redistribution only on unmoderated USENET newsgroups.