/* Knight and knaves: The whole truth and nothing but the truth Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" """ Puzzle 71. The whole truth and nothing but the truth On a famous island in the Pacific Ocean (whose name I forgot) live three tribes: the Whites, who always tell the truth; the Blacks, who always tell lies; and the Greys, who lie and tell the truth alternatively (although their first answer may be either truth or lie). These natives always gather in groups of three, with one representative of each tribe in the group. I approached such a group of three natives, and had the following con- versation with the first native: "Are you the White, the Black, or the Grey?" "I am the Grey". "And what about your friend here?" "He is a Black". "So, your other friend is the White? " "Of course". Was the "other friend" a White, and if not, what was he? """ ss = [0,0,0] tribes = [0,1,2] First: Blacks Second: Whites Third: Greys 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 ?=> % three tribes: % the Whites, who always tell the truth; % the Blacks, who always tell lies; % and the Greys, who lie and tell the truth alternatively (although their first % answer may be either truth or lie). Blacks = 0, Whites = 1, Greys = 2, Tribes = [First,Second,Third], Tribes :: [Blacks,Whites,Greys], % The first, second, and third statement % of the same person (from one of the tribes) Ss = [FirstS,SecondS,ThirdS], Ss :: 0..1, % Group of the three different tribes all_different(Tribes), % Same person is speaking three times % "Are you the White, the Black, or the Grey?" "I am the Grey". FirstS #<=> First #= Greys, % "And what about your friend here?" "He is a Black". SecondS #<=> Second #= Blacks, % "So, your other friend is the White?" "Of course". ThirdS #<=> Third #= Whites, First #= Whites #=> (FirstS #= 1 #/\ SecondS #= 1 #/\ ThirdS #= 1), First #= Blacks #=> (FirstS #= 0 #/\ SecondS #= 0 #/\ ThirdS #= 0), First #= Greys #=> ( (FirstS #= 1 #/\ SecondS #= 0 #/\ ThirdS #= 1) #\/ (FirstS #= 0 #/\ SecondS #= 1 #/\ ThirdS #= 0) ), Vars = Ss ++ Tribes, solve(Vars), println(ss=Ss), println(tribes=Tribes), Map = new_map([0="Blacks",1="Whites",2="Greys"]), printf("First: %w Second: %w Third: %w\n",Map.get(First), Map.get(Second), Map.get(Third)), nl, fail, nl. go => true.