/* Knight and knaves: Jim, Jon, and Joe in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" """ Puzzle 68. Jim, Jon, and Joe On the island of knights and knaves, knights always tell the truth, while knaves always lie. You are approached by three people: Jim, Jon, and Joe. Jim says: "Joe is a knave or I am a knight". Jon says, "Jim could claim that I am a knave". Joe says, "Neither Jim nor Jon are knights". What are they actually? (taken from Popular mechanics - www. popularmechanics.com/science/math) """ [0,0,1] Jim: Knave Jon: Knave Joe: Knight 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 ?=> Knave = 0, Knight = 1, Ps = [Jim,Jon,Joe], Ps :: [Knave,Knight], Jim #<=> (Joe #= Knave #\/ Jim #= Knight), Jon #<=> (Jim #<=> Jon #= Knave), Joe #<=> (Jim #!= Knight #/\ Jon #!= Knight), Vars = [Jim,Jon,Joe], solve(Vars), println(Vars), Map = new_map([0="Knave",1="Knight"]), printf("Jim: %w Jon: %w Joe: %w\n",Map.get(Jim), Map.get(Jon),Map.get(Joe)), fail, nl. go => true.