/* Stolen money problem in Picat. From Richard Wiseman: "it's the Friday Puzzle" http://richardwiseman.wordpress.com/2013/06/14/its-the-friday-puzzle-215/ """ The police know that either Dick, Jack, Sally, or Jimmy have stolen some money. Each suspects makes a statement, but only one of the statements is true. Dick said, "I didn’t do it". Jack said, "Dick is lying". Sally said, "Jack is lying". Jimmy said, "Jack did it". Who committed the crime? """ Model created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> L = [Dick,Jack,Sally,Jimmy], L :: 0..1, Names = ["Dick","Jack","Sally","Jimmy"], % Dick said, "I didn’t do it". Dick #=> (Dick #= 0), % Jack said, "Dick is lying". Jack #=> (Dick #= 1), % This is the result of Jack's statement % Sally said, "Jack is lying". Sally #=> (Dick #= 0), % This is the result of Sally's statement % Jimmy said, "Jack did it". Jimmy #=> (Jack #= 1), % Only one statement is true sum(L) #= 1, solve(L), writeln(L), println([N : {I,N} in zip(1..4,Names), L[I] == 1]), fail. go => true.