% Harry Potter and the seven potions perm([],[]). perm(X,[Y|Z]):-select(X,Y,R),perm(R,Z). puzzle(Potions, Dwarf, Giant):- Potions=[P1,P2,P3,P4,P5,P6,P7], F=forward, B=back, W=wine, P=poison, perm(Potions, [F,B,W,W,P,P,P]), P1\==W, (P2\==W; P1=P), (P3\==W; P2=P), (P4\==W; P3=P), (P5\==W; P4=P), (P6\==W; P5=P), (P7\==W; P6=P), P1\==P7, P1\==F, P7\==F, P2==P6, select(Potions, Dwarf, BigPotions), member(Giant, BigPotions), Dwarf\==P, Giant\==P, P7=back, Dwarf=forward. solve(S):-setof([P,D,G],puzzle(P,D,G),S),member(T,S), write(T),nl,fail. :-print('solve(X), puzzle(X,Y,Z), ... loaded'). :-nl.