/* Thick as Thieves in Picat. From http://l4f.cecs.anu.edu.au/puzzles/expert/thick-as-thieves """ Following a robbery at Sparkles the Jeweller's, Inspector Korner of the Yard interviewed six of the usual suspects. He knew that the getaway car had been barely big enough to hold two, so he reckoned that at least four of them were innocent – but which ones? He also supposed that the innocent ones would tell the truth, while the guilty one or ones would lie. What they actually said was: ARTIE: "It wasn’t me." BILL: "Crackitt was in it up to his neck." CRACKITT: "No I wasn’t." DODGY: "If Crackitt did it, Bill did it with him." EDGY: "Nobody did it alone." FINGERS: "That’s right: it was Artie and Dodgy together." If the good inspector’s suppositions were correct, who dunnit? """ 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 => N = 6, Names = ["Artie","Bill","Crackitt","Dodgy","Edgy","Fingers"], % who dunnit X = [Artie,Bill,Crackitt,Dodgy,Edgy,Fingers], X :: 0..1, % who told the truth XT = [ArtieT,BillT,CrackittT,DodgyT,EdgyT,FingersT], XT :: 0..1, % ARTIE: "It wasn’t me." ArtieT #= 1 #<=> Artie #= 0, % BILL: "Crackitt was in it up to his neck." BillT #= 1 #<=> Crackitt #= 1, % CRACKITT: "No I wasn’t." CrackittT #= 1 #<=> Crackitt #= 0, % DODGY: "If Crackitt did it, Bill did it with him." DodgyT #= 1 #<=> (Crackitt #= 1 #=> Bill #= 1), % EDGY: "Nobody did it alone." EdgyT #= 1 #<=> sum(X) #> 1, % FINGERS: "That’s right: it was Artie and Dodgy together." FingersT #= 1 #<=> (Artie #= 1 #/\ Dodgy #= 1), sum(XT) #>= 4, % at least 4 innocent, i.e. told the truth sum(X) #<= 2, % at most 2 guilty foreach(I in 1..N) % if telling the truth <-> didn't do it XT[I] #= 1 #<=> X[I] #= 0 end, Vars = X ++ XT, solve(Vars), println('x '=X), println('xt'=XT), println("Guilty"=[Names[I] : I in 1..N, X[I] == 1]), println("Told truth"=[Names[I] : I in 1..N, XT[I] == 1]), nl, fail, nl.