/* Knight and knaves: Three goddesses in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" """ Puzzle 72. Three goddesses Three goddesses were sitting in an old Indian temple. Their names were Truth (always telling the truth), Lie (always lying), and Wisdom (sometimes lying). A visitor asked the one on the left: "Who is sitting next to you?" "Truth", she answered. Then he asked the one in the middle: "Who are you?" "Wisdom". Last, he asked the one on the right: "Who is your neighbour?" "Lie", she replied. And then it became clear who was who. """ ss = [0,0,1] type = [2,0,1] Left:Wisdom Middle:Lie Right:Truth 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 ?=> Lie = 0, Truth = 1, Wisdom = 2, % Types Type = [Left,Middle,Right], Type :: [Lie,Truth,Wisdom], % Statements Ss = [LeftS,MiddleS,RightS], Ss :: 0..1, all_different(Type), % A visitor asked the one on the left: "Who is sitting next to you?" "Truth", she answered. LeftS #<=> Middle #= Truth, % Then he asked the one in the middle: "Who are you?" "Wisdom". MiddleS #<=> Middle #= Wisdom, % Last, he asked the one on the right: "Who is your neighbour?" "Lie", she replied. RightS #<=> Middle #= Lie, % Consequences of the statement types foreach(I in 1..3) Type[I] #= Truth #=> Ss[I] #= 1, Type[I] #= Lie #=> Ss[I] #= 0 end, Vars = Ss ++ Type, solve(Vars), println(ss=Ss), println(type=Type), Map = new_map([0="Lie",1="Truth",2="Wisdom"]), printf("Left:%w Middle:%w Right:%w\n",Map.get(Left), Map.get(Middle), Map.get(Right)), nl, fail, nl. go => true.