Chronology | Current Month | Current Thread | Current Date |
[Year List] [Month List (current year)] | [Date Index] [Thread Index] | [Thread Prev] [Thread Next] | [Date Prev] [Date Next] |
ANSWER TO THE CHAPTER I PUZZLE
All are liars:
(a) If A's statement is true, then B's denial is false, and B is a
liar. But if B is a liar, then A's statement is false. Therefore A's
statement cannot be true and A is a liar.
(b) If B's statement is true then either B or C must be the truth
teller, since we know that A is not. But if C is the truth teller,
then
B cannot be, making B's statement false. Thus, either B is the
only truth teller, or B is a liar.
(c) If B is a truth teller, then C's statement is true. But If B is a
truth teller, then B must be the ONLY truth teller, so C's
statement must be false. Thus C is a liar, and C's statement must
be a lie, making B's statement false and C's statement must be a
lie, making B's statement false.
I agree with the book's answer; I wrote a little perl program
to generate and check the truth table. The output is
A B C op(A) op(B) op(C) agrees?
----- ----- ----- ----- ----- ----- -------
false false false false false false yes
false false true false true false no
false true false false true true no
false true true false false true no
true false false false true false no
true false true false false false no
true true false false false true no
true true true true false true no
where the first three columns are the 'states' of the 3 men
('false' means 'liar'), the next three columns are the
correctness of the opinions held by the men ('false' means
that their voiced opinion does not match the known state
of the three men), and the last column indicates agreement,
i.e. are all persons who are liars actually lying, and vice
versa.
The script follows. Note that it is (relatively) easily
generalized to arbitrary numbers of people and opinions.
Note also that arbitrary numeric values of 'true' and
'false' generate the correct truth table. :-)
Regards,
John
==================== 3dudes.pl ====================
#!/usr/bin/perl -w
#--------------------------------------------------------
# define truth and falsity
#--------------------------------------------------------
$false = 0;
$true = 1;
#--------------------------------------------------------
# define array containing both truth and falsity
#--------------------------------------------------------
@truefalse = ($false,$true);
#--------------------------------------------------------
# define string versions of truth and falsity
#--------------------------------------------------------
$s{$false} = 'false';
$s{$true} = 'true';
#--------------------------------------------------------
# define functions that describe the 3 men's
# opinions about truth and falsity
#
# A: "There are 3 truthtellers here".
# B: "No, only 1 of us is a truthteller."
# C: "The second person is telling the truth."
#
# each function below returns 'true' if the
# three inputs agree with the given person's
# statement, false otherwise
#
#--------------------------------------------------------
sub op_A {
local($A,$B,$C) = @_;
return(
(($A == $true) and ($B == $true) and ($C == $true)) ? $true : $false
);
}
sub op_B {
local($A,$B,$C) = @_;
return(
(
(($A == $true) and ($B == $false) and ($C == $false)) or
(($A == $false) and ($B == $true) and ($C == $false)) or
(($A == $false) and ($B == $false) and ($C == $true))
) ? $true : $false
);
}
sub op_C {
local($A,$B,$C) = @_;
return(($B == $true) ? $true : $false);
}
#--------------------------------------------------------
# see who's right
#--------------------------------------------------------
print STDOUT " A B C op(A) op(B) op(C) agrees?\n";
print STDOUT "----- ----- ----- ----- ----- ----- -------\n";
foreach $A (@truefalse) {
foreach $B (@truefalse) {
foreach $C (@truefalse) {
$t{'A'} = &op_A($A,$B,$C); # evaluate A's opinion
$t{'B'} = &op_B($A,$B,$C); # evaluate B's opinion
$t{'C'} = &op_C($A,$B,$C); # evaluate C's opinion
printf STDOUT "%5s %5s %5s ", $s{$A}, $s{$B}, $s{$C};
printf STDOUT "%5s ", $s{$t{'A'}};
printf STDOUT "%5s ", $s{$t{'B'}};
printf STDOUT "%5s ", $s{$t{'C'}};
if (($t{'A'} == $A) and ($t{'B'} == $B) and ($t{'C'} == $C)) {
print STDOUT " yes";
} else {
print STDOUT " no";
}
print STDOUT "\n";
}
}
}