/* Werewolfes II (Smullyan) puzzle in Picat. From Martin Chlond Integer Programming Puzzles: http://www.chlond.demon.co.uk/puzzles/puzzles3.html, puzzle nr. 9. Description : Werewolves II Source : Smullyan, R., (1978), What is the Name of this Book?, Prentice-Hall This model was inspired by the XPress Mosel model created by Martin Chlond. http://www.chlond.demon.co.uk/puzzles/sol3s9.html This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => Person = 3, X = new_list(Person), % x(i) = 1 if person i is a knight, 0 if a knave X :: 0..1, Y = new_list(Person), % y(i) = 1 if person i is a werewolf, 0 otherwise Y :: 0..1, Z #= sum([X[I]+9*X[3] : I in 1..Person]), % only one is a werewolf sum(Y) #= 1, % if statement 1 is true then set x(1) = 1, else 0 Y[1] - 9*X[1] #<= 0, Y[1] - X[1] #>= 0, % if statement 2 is true then set x(2) = 1, else 0 Y[2] - 9*X[2] #<= 0, Y[2] - X[2] #>= 0, % if statement 3 is true then set x(3) = 1, else 0 sum([X[I]+9*X[3] : I in 1..Person]) #>= 2, sum([X[I]+9*X[3] : I in 1..Person]) #<= 28, Vars = X ++ Y ++ [Z], solve(Vars), println(z=Z), println(x=X), println(y=Y), nl, fail, nl. go => true.