This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/CLPQR/clpqr/examples/monash/zebra
vsc e5f4633c39 This commit was generated by cvs2svn to compensate for changes in r4,
which included commits to RCS files with non-trunk default branches.


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@5 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
2001-04-09 19:54:03 +00:00

63 lines
2.2 KiB
Plaintext

/*
**********************************************************************
*
* CLP(R) Version 2.0 (Example Programs Release)
* (C) Copyright, March 1986, Monash University
*
**********************************************************************
*/
%
% A program to solve the Zebra Puzzle.
%
zebra(Zebraowner,Drinkswater) :-
houses(s(s(s(s(s(zero))))), List),
member(house( red, englishman, _, _, _) ,List),
member(house( _, spaniard, dog, _, _) ,List),
member(house(green, _, _, coffee, _) ,List),
member(house( _, ukrainian, _, tea, _) ,List),
sublist([house(ivory, _, _, _, _) ,
house(green, _, _, _, _)],List),
member(house( _, _,snail, _,old_gold),List),
member(house(yellow, _, _, _, kools),List),
eq([H1,H2,house( _, _, _, milk, _),H4,H5], List),
eq([house( _, norwegian, _, _, _)|Hrest], List),
nextto(house( _, _, _, _,chesterfield),
house( _, _, fox, _, _),List),
nextto(house( _, _, _, _, kools),
house( _, _,horse, _, _),List),
member(house( _, _, _, orange,lucky_strike),List),
member(house( _, japanese, _, _,parliaments),List),
nextto(house( _, norwegian, _, _, _),
house( blue, _, _, _, _),List),
member(house( _, Drinkswater, _, water, _),List),
member(house( _, Zebraowner,zebra, _, _),List).
eq(X, X).
houses(zero, []).
houses(s(N), [house(Color,Nat,Pet,Drink,Cig)|List]) :- houses(N, List).
member(X, [X|R]).
member(X, [Y|R]) :- member(X, R).
sublist(S, L) :- append(S, S2, L).
sublist(S, [H|T]) :- sublist(S, T).
append([], L, L).
append([X|R], Y, [X|T]) :- append(R, Y, T).
nextto(H1, H2, L) :- sublist([H1, H2], L).
nextto(H1, H2, L) :- sublist([H2, H1], L).
go :-
zebra(Zebraowner, Drinkwater),
printf("Zebraowner = %, Drinkwater = %\n", [Zebraowner, Drinkwater]).
% Answer:
% Zebraowner = japanese, Drinkwater = norwegian
?- printf("\n>>> Sample goal: go/0\n", []).