% 00. Fuenf Haeuser stehen in einer Reihe.mit je einer Farbe % 01. Jedes Haus hat eine andere Farbe % 02. In jedem Haus wohnt eine Person einer anderen Nationalitaet % 03. Jeder Hausbewohner bevorzugt ein bestimmtes Getraenk, raucht eine % bestimmte Zigarettenmarke und haelt ein bestimmtes Haustier % 04. KEINE der 5 Personen trinkt das gleiche Getraenk, raucht die gleichen % Zigaretten oder haelt das gleiche Tier, wie einer seiner Nachbarn % Frage: Wem gehoert der Fisch???? house(1). house(2). house(3). house(4). house(5). left(1,2). left(2,3). left(3,4). left(4,5). % left(5,1). % putting the houses in a circle leaves additional solutions hasleft(X) :- left(Y,X). hasright(X) :- left(X,Y). leftmost(X) :- house(X), not hasleft(X). rightmost(X) :- house(X), not hasright(X). nat(gb). nat(s). nat(dk). nat(n). nat(d). 1{lives(gb,X), lives(s,X), lives(dk,X), lives(n,X), lives(d,X)}1 :- house(X). col(red). col(green). col(white). col(yellow). col(blue). 1{color(red,X), color(green,X), color(white,X), color(yellow,X), color(blue,X)}1 :- house(X). cig(pallmall). cig(dunhill). cig(marlboro). cig(winfield). cig(rothmans). 1{smokes(pallmall,X), smokes(dunhill,X), smokes(marlboro,X), smokes(winfield,X), smokes(rothmans,X)}1 :- house(X). drink(tea). drink(coffee). drink(water). drink(milk). drink(beer). 1{drinks(tea,X), drinks(coffee,X), drinks(water,X), drinks(milk,X), drinks(beer,X)}1 :- house(X). ani(dog). ani(bird). ani(fish). ani(cat). ani(horse). 1{animal(dog,X), animal(bird,X), animal(fish,X), animal(cat,X), animal(horse,X)}1 :- house(X). %%%%%% assert that no person lives in two houses etc: % two alternatives: via choice, % or as denials % 1{lives(X,1), lives(X,2), lives(X,3), lives(X,4), lives(X,5)}1 :- nat(X). % 1{color(X,1), color(X,2), color(X,3), color(X,4), color(X,5)}1 :- col(X). % 1{smokes(X,1), smokes(X,2), smokes(X,3), smokes(X,4), smokes(X,5)}1 :- cig(X). % 1{drinks(X,1), drinks(X,2), drinks(X,3), drinks(X,4), drinks(X,5)}1 :- drink(X). % 1{animal(X,1), animal(X,2), animal(X,3), animal(X,4), animal(X,5)}1 :- ani(X). :- lives(X,H1), lives(X,H2), nat(X), house(H1), house(H2), H1 != H2. :- color(X,H1), color(X,H2), col(X), house(H1), house(H2), H1 != H2. :- smokes(X,H1), smokes(X,H2), cig(X), house(H1), house(H2), H1 != H2. :- drinks(X,H1), drinks(X,H2), drink(X), house(H1), house(H2), H1 != H2. :- animal(X,H1), animal(X,H2), ani(X), house(H1), house(H2), H1 != H2. %Note: it is sufficient to fix one direction of each hint in a rule % 01. Der Brite lebt im roten Haus lives(gb,X) :- color(red,X), house(X). %color(red,X) :- lives(gb,X), house(X). % 02. Der Schwede haelt einen Hund lives(s,X) :- animal(dog,X), house(X). %animal(dog,X):-lives(s,X), house(X). % 03. Der Daene trinkt gerne Tee lives(dk,X) :- drinks(tea,X), house(X). %drinks(tea,X) :- lives(dk,X), house(X). % 04. Das gruene Haus steht direkt links vom weissen Haus color(green,X) :- left(X,Y), color(white,Y). %color(white,Y) :- left(X,Y), color(green,X). % 05. Der Besitzer des gruenen Hauses trinkt gerne Kaffee color(green,X) :- drinks(coffee,X), house(X). %drinks(coffee,X) :- color(green,X), house(X). % 06. Die Person, die Pall Mall raucht, haelt einen Vogel smokes(pallmall,X) :- animal(bird,X), house(X). %animal(bird,X) :- smokes(pallmall,X), house(X). % 07. Der Mann, der im mittleren Haus wohnt, trinkt gerne Milch drinks(milk,3). % 08. Der Besitzer des gelben Hauses raucht Dunhill smokes(dunhill,X) :- color(yellow,X), house(X). %color(yellow,X) :- smokes(dunhill,X), house(X). % 09. Der Norweger wohnt in dem ganz links stehenden Haus lives(n,1). % 10. Der Marlboro-Raucher wohnt neben dem, der eine Katze haelt 1{smokes(marlboro,X), smokes(marlboro,Z)}1 :- animal(cat,Y), left(X,Y), left(Y,Z). smokes(marlboro,X) :- animal(cat,Y), left(X,Y), rightmost(Y). smokes(marlboro,Z) :- animal(cat,Y), leftmost(Y), left(Y,Z). %1{animal(cat,X), animal(cat,Z)}1 % :- smokes(marlboro,Y), left(X,Y), left(Y,Z). %animal(cat,X) % :- smokes(marlboro,Y), left(X,Y), rightmost(Y). %animal(cat,Z) % :- smokes(marlboro,Y), leftmost(Y), left(Y,Z). % 11. Der Mann, der ein Pferd haelt, wohnt neben dem, der Dunhill raucht 1{animal(horse,X), animal(horse,Z)}1 :- smokes(dunhill,Y), left(X,Y), left(Y,Z). animal(horse,X) :- smokes(dunhill,Y), left(X,Y), rightmost(Y). animal(horse,Z) :- smokes(dunhill,Y), leftmost(Y), left(Y,Z). %1{smokes(dunhill,X), smokes(dunhill,Z)}1 % :- animal(horse,Y), left(X,Y), left(Y,Z). %smokes(dunhill,X) % :- animal(horse,Y), left(X,Y), rightmost(Y). %smokes(dunhill,Z) % :- animal(horse,Y), leftmost(Y), left(Y,Z). % 12. Der Winfield-Raucher trinkt gerne Bier smokes(winfield,X) :- drinks(beer,X), house(X). %drinks(beer,X) :- smokes(winfield,X), house(X). % 13. Neben dem blauen Haus wohnt der Norweger 1{lives(n,X), lives(n,Z)}1 :- color(blue,Y), left(X,Y), left(Y,Z). lives(n,X) :- color(blue,Y), left(X,Y), rightmost(Y). lives(n,Z) :- color(blue,Y), leftmost(Y), left(Y,Z). %1{color(blue,X), color(blue,Z)}1 % :- lives(n,Y), left(X,Y), left(Y,Z). %color(blue,X) % :- lives(n,Y), left(X,Y), rightmost(Y). %color(blue,Z) % :- lives(n,Y), leftmost(Y), left(Y,Z). smokes(rothmans,X) :- lives(d,X), house(X). %lives(d,X) :- smokes(rothmans,X), house(X). % 15. Derjenige, der Marlboro raucht, hat einen Nachbarn, der Wasser trinkt 1{drinks(water,X), drinks(water,Z)}1 :- smokes(marlboro,Y), left(X,Y), left(Y,Z). drinks(water,X) :- smokes(marlboro,Y), left(X,Y), rightmost(Y). drinks(water,Z) :- smokes(marlboro,Y), leftmost(Y), left(Y,Z). %1{smokes(marlboro,X), smokes(marlboro,Z)}1 % :- drinks(water,Y), left(X,Y), left(Y,Z). %smokes(marlboro,X) % :- drinks(water,Y), left(X,Y), rightmost(Y). %smokes(marlboro,Z) % :- drinks(water,Y), leftmost(Y), left(Y,Z).