How to solve the liar problem?
Have you seen, that Mathematica is capable of many boolean computations using special boolean functions? Let's assume someone from the island makes a statement, then when the statement is true, whether or not he tells the statement is true, depends on whether or not he is a truth-teller. When we know, which kind he is, we know the correct statement through what he says. Therefore, let's define a function for this and check the truth-table
trueStatement[statement_,isTruthTeller_]:=!Xor[statement,isTruthTeller]
BooleanTable[{a,b,trueStatement[a,b]},{a,b}]//TableForm
(*
True True True
True False False
False True False
False False True
*)
So, if A says a statement is true and A is a truth-teller, the statement is true for sure. On the other hand, if A is not a truth-teller, then the real statement is false.
Now we want to transform the two statements
A said: "B is a truth-teller." B said: "We two are different kinds of people."
without knowing whether a
or b
are liars or truth-tellers
eq = trueStatement[b, a] && trueStatement[a == ! b, b]
The statements read as: a
says that b
is a truth-teller and b
says, that a
is not of the same kind as b
. Now we can simply do
SatisfiabilityInstances[eq, {a, b}]
(* {{False, False}} *)
Therefore, both, a
and b
are liars.
Cases[Tuples[{True, False}, 2], {a_, b_} /;
Equivalent[a, b] && Equivalent[b, Xor[a, b]]]
(*{{False, False}}*)
FindInstance[Equivalent[a, b] && Equivalent[b, Xor[a, b]], {a, b}, Booleans]
(*{{a -> False, b -> False}}*)