/* The third trial (Smullyan) puzzle in Picat. From Martin Chlond Integer Programming Puzzles: http://www.chlond.demon.co.uk/puzzles/puzzles3.html, puzzle nr. 5. Description : The Third 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/sol3s5.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 D = 1..Door, P = 1..Prize, % 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 D) sum([X[I,J] : J in P]) #= 1 end, % if statement on door 1 is true [i.e. x[1,2]+x[2,1]>=1] then set t[1] = 1, else t[1] = 0 X[1,2]+X[2,1]-T[1] #<= 0, X[1,2]+X[2,1]-T[1] #>= 0, % if statement on door 2 is true then set t[2] = 1, else t[2] = 0 T[2] #= X[1,1], % either both statements true or both false T[1] #= T[2], Vars = X.vars ++ T, solve(Vars), println(x=X), println(t=T), fail, nl.