/* The second trial (Smullyan) puzzle in Picat. From Martin Chlond Integer Programming Puzzles: http://www.chlond.demon.co.uk/puzzles/puzzles3.html, puzzle nr. 4. Description : The Second Trial Source : Smullyan, R., (1991), The Lady or The Tiger, Oxford University Press This model was inspired by the XPress Mosel model created by Martin Chlond. http://www.chlond.demon.co.uk/puzzles/sol3s4.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 => Door = 2, Prize = 2, % 1 = Lady, 2 = Tiger % x(i,j) = 1 if door i hides prize j, else 0 X = new_array(Door,Prize), X :: 0..1, % t(i) = 1 if statement on door i is true, else 0 T = new_list(Door), T :: 0..1, % each door hides 1 prize foreach(I in 1..Door) sum([X[I,J] : J in 1..Prize]) #= 1 end, % if statement on door 1 is true then t[1] = 1, else t[1] = 0 X[1,1]+X[2,1]-2*T[1] #<= 0, X[1,1]+X[2,1]-T[1] #>= 0, % if statement on door 2 is true then t[2] = 1, else t[2] = 0 T[2] #= X[1,2], % statements either both true or both false T[1] #= T[2], Vars = X.vars ++ T.vars, solve(Vars), println(X), println(T), fail, nl.