%%%% Zebra puzzle % % shirt: black, blue, pink, yellow % name: andrew, brian, samuel, yousef % produce: apples, corn, onions, tomatoes % price: $2.0, $2.5, $4.0, $6.0 % % The farmer charging $2.00 per pound is in the third position. % The farmer charging $2.50 per pound is in the second position. % The farmer selling Onions is immediately before the farmer wearing the Black shirt. % Brian is the farmer selling Apples. % The farmer wearing the Blue shirt is in the last position. % The farmer wearing the Pink shirt is immediately after the one charging $2.50 per pound. % Andrew is the vendor in the second position. % The farmer charging $6.00 per pound is in the first position. % Yousef is the vendor in the last position. % The farmer wearing the Black shirt is selling Tomatoes. % The vendor selling Corn is at one of the ends. in_position([E|_],E,1). in_position([_|T],E,N) :- N1 is N - 1, in_position(T,E,N1). immediately_before([E1|_],E1,[_,E2|_],E2). immediately_before([_|T1],E1,[_|T2],E2) :- immediately_before(T1,E1,T2,E2). immediately_after(L1,E1,L2,E2) :- immediately_before(L2,E2,L1,E1). the_same([E1|_],E1,[E2|_],E2). the_same([_|T1],E1,[_|T2],E2) :- the_same(T1,E1,T2,E2). is_last([E],E). is_last([_|T],E) :- is_last(T,E). at_one_end([E|_],E). at_one_end(L,E) :- is_last(L,E). zebra(Shirt,Name,Produce,Price) :- permutation(Shirt,[black, blue, pink, yellow]), permutation(Name,[andrew, brian, samuel, yousef]), permutation(Produce,[apples, corn, onions, tomatoes]), permutation(Price,[$2.0, $2.5, $4.0, $6.0]), in_position(Price,$2.0,3), in_position(Price,$2.5,2), immediately_before(Produce,onions,Shirt,black), the_same(Name,brian,Produce,apples), is_last(Shirt,blue), immediately_after(Shirt,pink,Price,$2.5), in_position(Name,andrew,2), in_position(Price,$6.0,1), is_last(Name,yousef), the_same(Shirt,black,Produce,tomatoes), at_one_end(Produce,corn). zebra(Shirt,Name,Produce,Price).