/* Knights and Knaves: Is one of you a knight? in Picat. From TPTP: PUZ035-6.p """ -------------------------------------------------------------------------- File : PUZ035-6 : TPTP v8.2.0. Released v2.0.0. Domain : Puzzles Problem : Knights and Knaves #36 Version : [Sto95] axioms. Theorem formulation : Definite answer "no". English : On an island, there live exactly two types of people: knights and knaves. Knights always tell the truth and knaves always lie. I landed on the island, met two inhabitants, asked one of them: "Is one of you a knight?" and he answered me. What can be said about the types of the asked and the other person depending on the answer I get? Refs : [Smu78] Smullyan (1978), What is the Name of This Book? The Ri : [Sto95] Stolzenburg (1995), Email to Geoff Sutcliffe. : [BFS95] Baumgartner et al. (1995), Model Elimination, Logic Pr : [BFS97] Baumgartner et al. (1997), Computing Answers with Mode Source : [Sto95] Names : Status : Unsatisfiable Rating : 0.00 v7.1.0, 0.17 v7.0.0, 0.12 v6.3.0, 0.14 v6.2.0, 0.00 v2.1.0 Syntax : Number of clauses : 11 ( 1 unt; 3 nHn; 7 RR) Number of literals : 24 ( 0 equ; 13 neg) Maximal clause size : 3 ( 2 avg) Maximal term depth : 4 ( 1 avg) Number of predicates : 2 ( 2 usr; 0 prp; 1-2 aty) Number of functors : 7 ( 7 usr; 4 con; 0-2 aty) Number of variables : 16 ( 4 sgn) SPC : CNF_UNS_RFO_NEQ_NHN """ The question is "Is either of you a Knight?" First, is "either" an inclusive either or is it exclusive? Second, what did A answer: yes or no Here are the four cases type = inclusive either answer = no A: Knave B: Knight answer = yes A: Knave B: Knave A: Knight B: Knave A: Knight B: Knight type = exclusive either answer = no A: Knave B: Knight A: Knight B: Knight answer = yes A: Knave B: Knave A: Knight B: Knave 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 ?=> println("Is one of you a Knight?"), member(Type,["Inclusive either","Exclusive either"]), nl, println(type=Type), member(Answer,0..1), println(answer=cond(Answer==0,"no","yes")), Knave = 0, Knight = 1, Ps = [A,B], Ps :: [Knave,Knight], % I landed on the island, met two inhabitants, asked one of % them: "Is one of you a knight?" and he answered me. What can % be said about the types of the asked and the other person % depending on the answer I get? (Type == "Inclusive either" -> Statement #= (A #= Knight #\/ B #= Knight) ; Statement #= (A #= Knight #^ B #= Knight) ), A #<=> (Statement #= Answer), solve(Ps), Map = new_map([0="Knave",1="Knight"]), printf("A: %w B: %w\n",Map.get(A),Map.get(B)), fail, nl. go => true.