There are three people (Alex, Brook and Cody), one of whom is a knight, one a knave, and one a spy.The knight always tells the truth, the knave always lies, and the spy can either lie or tell the truth. Alex says: "Cody is a knave." Brook says: "Alex is a knight." Cody says: "I am the spy." Who is the knight, who the knave, and who the spy? Solve this puzzle by prolog clpb
Asked
Active
Viewed 229 times
0
-
1You need to add an attempted solution in your question to get a response. This will almost certainly require you to ask a more specific question than "do X using Y". – madgen May 17 '20 at 11:53
-
:- use_module(library(clpb)). example_knights(1, [C]) :- ?- sat(A=:= ~C). % Example 2: A says: "I am a knave, but B isn't." % B says: " A is a knight." example_knights(2, [A]) :- ?- sat(B=:= A ). % Example 3: A says: "At least one of us is a knave." %C says: "I am the spy." example_knights(3, [C]) :- ?- sat(C=:=(C)). I was trying to do the basic of it but it is too short for giving an answer. And using matrix 3by 3, I was struggling of how to write that code in prolog – user13559963 May 17 '20 at 12:06
-
can you please edit your *question* and add the code in a formatted manner. Also this code does not have a matrix, please be clear about what you intend the code to do but what is does instead. – madgen May 17 '20 at 12:14
-
Definitely look at [Knights and Knaves in Prolog](https://www.youtube.com/watch?v=oEAa2pQKqQU) – David Tonhofer May 17 '20 at 13:10