You're once again on the island of Knights, Knaves, and Liars. You meet 6 natives who are all different ages between 20 and 50. They make the following statements to you:
Andy says:
Brad is a Liar.
Fred is a Liar.
I'm one year older than Brad.
I'm three years older than Chet.
The sum of our ages is divisible by 3.
Brad says:
Chet is a Liar.
Andy is a Liar.
I'm one year older than Chet.
I'm three years older than Doug.
My age is divisible by 5.
Chet says:
Doug is a Liar.
Brad is a Liar.
I'm one year older than Doug.
I'm three years older than Eddy.
My age is divisible by 2.
Doug says:
Eddy is a Liar.
Chet is a Liar.
I'm one year older than Eddy.
I'm three years older than Fred.
I'm the oldest.
Eddy says:
Fred is a Liar.
Doug is a Liar.
I'm one year older than Fred.
I'm three years older than Andy.
The sum of our ages is divisible by 11.
Fred says:
Andy is a Liar.
Eddy is a Liar.
I'm one year older than Andy.
I'm three years older than Brad.
The sum of our ages is a perfect square.
Figure out the ages of the six natives.
DECLARE SUB permute (a$)
DIM used(20 TO 50)
OPEN "liar logic 2.txt" FOR OUTPUT AS #2
CLS
FOR At = 0 TO 3 'Liar, Kv-2nd true, Kv-1st true, Kt
a1 = -(At \ 2): a2 = -(At MOD 2)
FOR Bt = 0 TO 3
b1 = -(Bt \ 2): b2 = -(Bt MOD 2)
FOR Ct = 0 TO 3
c1 = -(Ct \ 2): c2 = -(Ct MOD 2)
FOR Dt = 0 TO 3
d1 = -(Dt \ 2): d2 = -(Dt MOD 2)
FOR Et = 0 TO 3
e1 = -(Et \ 2): e2 = -(Et MOD 2)
FOR Ft = 0 TO 3
f1 = -(Ft \ 2): f2 = -(Ft MOD 2)
good = 1
IF a1 <> (Bt = 0) THEN good = 0
IF a2 <> (Ft = 0) THEN good = 0
IF b1 <> (Ct = 0) THEN good = 0
IF b2 <> (At = 0) THEN good = 0
IF c1 <> (Dt = 0) THEN good = 0
IF c2 <> (Bt = 0) THEN good = 0
IF d1 <> (Et = 0) THEN good = 0
IF d2 <> (Ct = 0) THEN good = 0
IF e1 <> (Ft = 0) THEN good = 0
IF e2 <> (Dt = 0) THEN good = 0
IF f1 <> (At = 0) THEN good = 0
IF f2 <> (Et = 0) THEN good = 0
IF good THEN
PRINT
PRINT At; Bt; Ct; Dt; Et; Ft; "*"
PRINT #2, At; Bt; Ct; Dt; Et; Ft; "*"
FOR aage = 20 TO 50
used(aage) = 1
PRINT aage;
FOR bage = 20 TO 50
IF used(bage) = 0 THEN
used(bage) = 1
FOR cage = 20 TO 50
IF used(cage) = 0 THEN
used(cage) = 1
FOR dage = 20 TO 50
IF used(dage) = 0 THEN
used(dage) = 1
FOR eage = 20 TO 50
IF used(eage) = 0 THEN
used(eage) = 1
FOR fage = 20 TO 50
IF used(fage) = 0 THEN
used(fage) = 1
sum = aage + bage + cage + dage + eage + fage
good = 1
IF a1 <> (aage = bage + 1) THEN good = 0
IF a2 <> (aage = cage + 3) THEN good = 0
IF a1 <> (sum MOD 3 = 0) THEN good = 0
IF good THEN
IF b1 <> (bage = cage + 1) THEN good = 0
IF b2 <> (bage = dage + 3) THEN good = 0
IF b1 <> (bage MOD 5 = 0) THEN good = 0
IF good THEN
IF c1 <> (cage = dage + 1) THEN good = 0
IF c2 <> (cage = eage + 3) THEN good = 0
IF c1 <> (cage MOD 2 = 0) THEN good = 0
IF good THEN
IF d1 <> (dage = eage + 1) THEN good = 0
IF d2 <> (dage = fage + 3) THEN good = 0
IF d1 <> (dage > aage AND dage > bage AND dage > cage AND dage > eage AND dage > fage) THEN good = 0
IF good THEN
IF e1 <> (eage = fage + 1) THEN good = 0
IF e2 <> (eage = aage + 3) THEN good = 0
IF e1 <> (sum MOD 11 = 0) THEN good = 0
IF good THEN
IF f1 <> (fage = aage + 1) THEN good = 0
IF f2 <> (fage = bage + 3) THEN good = 0
sr = INT(SQR(sum) + .5)
IF f1 <> (sr * sr = sum) THEN good = 0
IF good THEN
PRINT
PRINT At; Bt; Ct; Dt; Et; Ft
PRINT aage; bage; cage; dage; eage; fage, sum, SQR(sum)
PRINT #2, aage; bage; cage; dage; eage; fage, sum, SQR(sum)
END IF
END IF
END IF
END IF
END IF
END IF
used(fage) = 0
END IF
NEXT fage
used(eage) = 0
END IF
NEXT eage
used(dage) = 0
END IF
NEXT dage
used(cage) = 0
END IF
NEXT cage
used(bage) = 0
END IF
NEXT bage
used(aage) = 0
NEXT aage
END IF
NEXT
NEXT
NEXT
NEXT
NEXT
NEXT
produces the following:
0 1 2 0 1 2 *
0 3 0 3 0 3 *
1 2 0 1 2 0 *
42 40 39 31 29 28 209 14.45683
2 0 1 2 0 1 *
3 0 3 0 3 0 *
Each line with an asterisk shows a set of native types, from Andy to Fred in order, that are consistent with their first two claims each. Zero represents a liar; 1 represents a knave who starts with a lie; 2, a knave who starts with a true statement; and 3, a knight.
Only one of these is followed by a set of ages consistent with their statements and types:
Andy is a 42-year-old knave, who started with a lie.
Brad is a 40-year-old knave, who started with a true statement.
Chet is a 39-year-old liar.
Doug is a 31-year-old knave, who started with a lie.
Eddy is a 29-year-old knave, who started with a true statement.
Fred is a 28-year-old liar.
209 is the sum of their ages, which is not a perfect square, but is divisible by 11.
|
Posted by Charlie
on 2014-03-17 16:25:04 |