🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #4281

The Zebra problem

#4281
From: Richard T. Ferris
Date: Wed, 14 Mar 1990 14:39
87 lines
3005 bytes
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
Technical Details
Message-ID: <21712@netnews.upenn.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!snorkelwacker!usc!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!dsinc!netnews.upenn.edu!eniac.seas.upenn.edu!ferris

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!snorkelwacker!usc!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!dsinc!netnews.upenn.edu!eniac.seas.upenn.edu!ferris
From: ferris@eniac.seas.upenn.edu (Richard T. Ferris)
Newsgroups: comp.lang.prolog
Subject: The Zebra problem
Summary: Can't get it to work
Message-ID: <21712@netnews.upenn.edu>
Date: 14 Mar 90 14:39:53 GMT
Sender: news@netnews.upenn.edu
Reply-To: ferris@eniac.seas.upenn.edu.UUCP (Richard T. Ferris)
Organization: University of Pennsylvania
Lines: 87