/* Who killed the Bosmer logic puzzle in Picat. From https://swi-prolog.discourse.group/t/similar-einstein-riddle/5142/6 """ A Bosmer, was slain. The Altmer claims the Dunmer is guilty. The Dunmer says the Khajiit did it. The Orc swears he didn’t kill the Bosmer. The Khajiit says the Dunmer is lying. If only one of these speaks the truth, who killed the Bosmer?"" """ Cf http://hakank.org/swi_prolog/who_killed_the_bosmer.pl http://hakank.org/webppl/who_killed_the_bosmer.wppl This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import v3_utils. % import util. import cp. main => go. go ?=> L = [altmer,dunmer,orc,khajiit], % Who speaks the truth? SpeaksTruth = [AltmerT,DunmerT,OrcT,KhajiitT], SpeaksTruth :: 0..1, % Who is guilty? Guilty = [AltmerG,DunmerG,OrcG,KhajiitG], Guilty :: 0..1, % A Bosmer, was slain. % The Altmer claims the Dunmer is guilty. AltmerT #<=> DunmerG, % The Dunmer says the Khajiit did it. DunmerT #<=> KhajiitG, % The Orc swears he didn’t kill the Bosmer. OrcT #<=> (OrcG #= 0), % The Khajiit says the Dunmer is lying. KhajiitT #<=> (DunmerT #= 0), % If only one of these speaks the truth, who killed the Bosmer?"" sum(SpeaksTruth) #= 1, % Only one is is guilty sum(Guilty) #= 1, solve(SpeaksTruth++Guilty), println(speaks_truth=SpeaksTruth), println('guilty '=Guilty), foreach(I in 1..4) if SpeaksTruth[I] == 1 then println(speaks_truth=L[I]) end, if Guilty[I] == 1 then println('guilty '=L[I]) end end, nl, fail, nl. go => true.