/* Costume ball problem in Picat. From Prolog code http://www.anselm.edu/internet/compsci/faculty_staff/mmalita/HOMEPAGE/logic/costume1.txt """ Author: (solution MM) From: Dell- Math Puzzles Logic Problems, Jan 2002 p.15 Title: The costume ball 1 Four couples in all Attended a costume ball. 2 The lady dressed as a cat Arrived with her husband Matt. 3 Two couples were already there, One man dressed like a bear. 4 First to arrive wasn't Vince, But he got there before the Prince. 5 The witch (not Sue) is married to Chuck, Who was dressed as Donald Duck. 6 Mary came in after Lou, Both were there before Sue. 7 The Gipsy arrived before Ann, Neither is wed to Batman. 8 If Snow White arrived after Tess, Then how was each couple dressed? ?- sol(I),write(I),fail. I= [[lou,bear,tess,gipsy], [vince,batman,mary,snow_white], [matt,prince,sue,cat], [chuck,donald_duck,ann,witch]] no There is only one solution. """ Note: This program generates 24 solutions (via fail), but all are the same. This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. % import cp. main => go. go => Sols = findall(Sol,start(Sol)), writeln(Sols.length), foreach(Sol in Sols) writeln(Sol) end, writeln(unique=Sols.remove_dups()), nl. verify(Verify) => Verify = [[lou,bear,tess,gipsy],[vince,batman,mary,snow_white],[matt,prince,sue,cat],[chuck,donald_duck,ann,witch]]. boy(Boy) => Boy = [vince,chuck,lou,matt]. girl(Girl) => Girl = [sue,mary,ann,sue]. costume_boy(CostumeBoy) => CostumeBoy = [batman,donald_duck,prince,bear]. costume_girl(CostumeGirl) => CostumeGirl = [witch,gipsy,cat,snow_white]. start(Sol) => boy(B),girl(W),costume_boy(C),costume_girl(Cw), Sol=[[M1,C1,W1,Cw1],[M2,C2,W2,Cw2],[M3,C3,W3,Cw3],[M4,C4,W4,Cw4]], % 1 member([matt,_,_,cat],Sol), % 2 Sol=[X1,X2,[matt,_,_,cat],_], % 3 (member(bear,X1) ; member(bear,X2)), % 3 before([vince,_,_,_],[_,prince,_,_],Sol), % 4 member([chuck,donald_duck,X,witch],Sol), % 5 before([lou,_,_,_],[_,_,mary,_],Sol), % 6 before([_,_,mary,_],[_,_,sue,_],Sol), % 6 before([_,G1,_,gipsy],[_,A1,ann,_],Sol), % 7 before([_,_,tess,_],[_,_,_,snow_white],Sol), % 8 set_equal([M1,M2,M3,M4],B), set_equal([C1,C2,C3,C4],C), set_equal([W1,W2,W3,W4],G), set_equal([Cw1,Cw2,Cw3,Cw4],Cw), vince != M1, % 4 not(X=sue), % 5 not(G1=batman), not(A1=batman). % 7 set_equal(P1,P2) => permutation(P1,P2). % From % http://www.anselm.edu/internet/compsci/faculty_staff/mmalita/HOMEPAGE/logic/bibmm.txt /* before (X,Y,List). Checks if X is before Y in the List. Starts from Left to right (normal order..). ?-before(a,c,[m,a,v,c,d]). yes */ before(X,Y,L) => append(_,[X|T],L), member(Y,T).