<div class="notebook"> <div class="nb-cell program" name="p1"> % Here is the riddle as stated by Einstein: % In a street there are five houses, painted five different colours. % - In each house lives a person of different nationality % - These five homeowners each drink a different kind of beverage, smoke different brand of cigar and keep a different pet % - Who drinks water? Who owns the zebra? % 1. There are five houses. % 2. The Englishman lives in the red house. % 3. The Spaniard owns the dog. % 4. Coffee is drunk in the green house. % 5. The Ukrainian drinks tea. % 6. The green house is immediately to the right of the ivory house. % 7. The Old Gold smoker owns snails. % 8. Kools are smoked in the yellow house. % 9. Milk is drunk in the middle house. % 10. The Norwegian lives in the first house. % 11. The man who smokes Chesterfields lives in the house next to the man with the fox. % 12. Kools are smoked in the house next to the house where the horse is kept. % 13. The Lucky Strike smoker drinks orange juice. % 14. The Japanese smokes Parliaments. % 15. The Norwegian lives next to the blue house. % 1. There are five houses. They maintain a list. houses(0, []) :- !. houses(N, [(_Person,_Color,_Drink,_Smoke,_Animal)|T]) :- N1 is N-1, houses(N1,T). % 2. The Englishman lives in the red house. rule2([(brit,red,_,_,_)|_]). rule2([_|T]) :- rule2(T). % 3. The Spaniard owns the dog. rule3([(spaniard,_,_,_,dog)|_]). rule3([_|T]) :- rule3(T). % 4. Coffee is drunk in the green house. rule4([(_,green,coffee,_,_)|_]). rule4([_|T]) :- rule4(T). % 5. The Ukrainian drinks tea. rule5([(ukranian,_,tea,_,_)|_]). rule5([_|T]) :- rule5(T). % 6. The green house is immediately to the right of the ivory house. rule6([(_,ivory,_,_,_),(_,green,_,_,_)|_]). rule6([_|T]) :- rule6(T). % 7. The Old Gold smoker owns snails. rule7([(_,_,_,old_gold,snake)|_]). rule7([_|T]) :- rule7(T). % 8. Kools are smoked in the yellow house. rule8([(_,yellow,_,kool,_)|_]). rule8([_|T]) :- rule8(T). % 9. Milk is drunk in the middle house. rule9([_,_,(_,_,milk,_,_),_,_]). rule9([_|T]) :- rule9(T). % 10. The Norwegian lives in the first house. rule10([(norwegian,_,_,_,_)|_]). % 11. The man who smokes Chesterfields lives in the house next to the man with the fox. rule11([(_,_,_,chesterfield,_),(_,_,_,_,fox)|_]). rule11([(_,_,_,_,fox),(_,_,_,chesterfield,_)|_]). rule11([_|T]) :- rule11(T). % 12. Kools are smoked in the house next to the house where the horse is kept. rule12([(_,_,_,kool,_),(_,_,_,_,horse)|_]). rule12([(_,_,_,_,horse),(_,_,_,kool,_)|_]). rule12([_|T]) :- rule12(T). % 13. The Lucky Strike smoker drinks orange juice. rule13([(_,_,orange,lucky_strike,_)|_]). rule13([_|T]) :- rule13(T). % 14. The Japanese smokes Parliaments. rule14([(japaneze,_,_,parliament,_)|_]). rule14([_|T]) :- rule14(T). % 15. The Norwegian lives next to the blue house. rule15([(norwegian,_,_,_,_),(_,blue,_,_,_)|_]). rule15([(_,blue,_,_,_),(norwegian,_,_,_,_)|_]). rule15([_|T]) :- rule15(T). % After that, we are to specify the questions: quest1(WaterDrinker,[(WaterDrinker,_,water,_,_)|_]). quest1(WaterDrinker,[_|T]) :- quest1(WaterDrinker,T). quest2(ZebraOwner,[(ZebraOwner,_,_,_,zebra)|_]). quest2(ZebraOwner,[_|T]) :- quest2(ZebraOwner,T). % Solutiontime! solution(Persons,WaterDrinker,ZebraOwner) :- houses(5,Persons), rule2(Persons), rule3(Persons), rule4(Persons), rule5(Persons), rule6(Persons), rule7(Persons), rule8(Persons), rule9(Persons), rule10(Persons), rule11(Persons), rule12(Persons), rule13(Persons), rule14(Persons), rule15(Persons), quest1(WaterDrinker,Persons), quest2(ZebraOwner,Persons). </div> </div>