% Harry Potter and the seven potions perm([],[]). perm(X,[Y|Z]):-select(Y,X,R),perm(R,Z). puzzle(Potions):- Potions=[P1,P2,P3,P4,P5,P6,P7], perm(Potions, [forward,back,wine,wine,poison,poison,poison]), % First clue -- Each wine bottle has poison on the left P1\==wine, (P2\==wine; P1=poison), (P3\==wine; P2=poison), (P4\==wine; P3=poison), (P5\==wine; P4=poison), (P6\==wine; P5=poison), (P7\==wine; P6=poison), % Second clue -- the ends are different P1\==P7, % Neither end moves you forward P1\==forward, P7\==forward, % Third clue -- look at the drawing for the biggest and smallest Dwarf=P3, Giant=P2, Dwarf\==poison, Giant\==poison, % Fourth clue -- second left and second on the right are the same P2==P6. solve(S):-setof(P,puzzle(P),S),member(T,S), write(T),nl,fail.