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]

Re: The world's first readable calculus [long]



I still do not know how to write the algorithm for solving Jack's
problem on a computer (see below). Any hints? I suppose that
algorithms coded in Fortran, True Basic or Pascal would be
nearly identical in terms of understanding the approach. [I do
not know Perl, C, C++, Java, etc. They keep introducing these
languages so fast that the usefulness of learning them becomes
questionable. I learned how to use a pencil over 60 years ago and
the skill remains very valuable. Same for geometry, algebra, etc.]
Ludwik Kowalski
---------------------------------------------------------
You are in a land where everyone is either a liar or a truthteller;
liars never tell the truth and truthtellers never lie. You need a
truthteller for a business deal. You have lunch with 3 people,
#1, #2, and #3 and ask if any of them is a truthteller. They know
each other in terms being or not being liars. Their answers are:

#1: "There are 3 truthtellers here".
#2: "No, only 1 of us is a truthteller."
#3: "The second person is telling the truth."

Which, if any, are the truthtellers?
---------------------------------------------------------
My notation: an array op$(3) <-- opinion of person #1, #2 and #3

thus: op$(1)="There are 3 truthtellers here".
op$(2)="No, only 1 of us is a truthteller."
op$(3)="The second person is telling the truth."

Array elements are strings. Each opinion can have two
values, 1 (truth) or 0 (false). This calls for another array
val(3,2) whose elements are 1 or 0.

val(1,1)=1 would mean that person #1 is telling the truth
val(1,0)=0 would mean that person #1 is not telling the truth
val(2,1)=1 would mean that person #2 is telling the truth
val(2,0)=0 would mean that person #2 is not telling the truth
val(3,1)=1 would mean that person #3 is telling the truth
val(3,0)=0 would mean that person #3 is not telling the truth

My program must assign values to elements of array val(,)
on the basis three strings supplied to it. In other words I want
op$() to be the input (typing three strings) and val(,) to be the
output. Assume I did not read the answers provided by a smart
human being (see below). For example, how can a computer be
made aware that op$(1) and op$(2) unconditionally contradict
each other while op$(2) and op$(3) may or may not be in
conflict?
--------------------------------------------------------
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.

John Trammell wrote:

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";

}
}
}