Alex, Bert, and Carl are taking a break from being main subjects in these logic puzzles, so Dave and Eddy decided to comment on the rarely seen Fred, Gary, and Hank.
Dave and Eddy are both knaves and each one makes four of the eight statements below. The statements are in order, but whether Dave or Eddy made any given statement is not known. Without knowing which statements are Dave's and which are Eddy's, can you determine the types of Fred, Gary, and Hank?
 Fred is a liar.
 Gary is a knave.
 Hank is a knight.
 Fred and Gary are the same type.
 Gary and Hank are different types.
 Fred is a knight.
 Hank is a knave.
 Gary is a liar.
In the sequence of true and false statements it doesn't matter which is Dave and which is Eddy, as each is a knave.
The sequence of true and false statements, given their being spoken by two knaves, and given the content about Fred, Gary and Hank, can only be F, F, T, F, T, T, F, T. If Dave is the first speaker, then any of the following speaker orders could produce this sequence of true and false. Below each sequence of speaker's initials is the truth value of the statement (0 for false, 1 for true), and below that, the types for each of Fred, Gary and Hank, using n for knight and l for liar (there is no knave in the group, other than Dave and Eddy):
dedddeee
00101101
fgh
nln
deddedee
00101101
fgh
nln
deeededd
00101101
fgh
nln
deeeeddd
00101101
fgh
nln
Also valid would be the same sequences, but with Dave and Eddy interchanged.
So Fred and Hank are knights and Gary is a liar.DECLARE SUB permute (a$)
CLS
s$ = "dddeeee"
hld$ = s$
DO
seq$ = "d" + s$
FOR f = 1 TO 3
ft$ = MID$("nvl", f, 1)
FOR g = 1 TO 3
gt$ = MID$("nvl", g, 1)
FOR h = 1 TO 3
ht$ = MID$("nvl", h, 1)
FOR d1 = 0 TO 1
FOR e1 = 0 TO 1
d = d1
e = e1
good = 1
FOR q = 1 TO 8
spkr$ = MID$(seq$, q, 1)
IF spkr$ = "d" THEN tv = d: d = 1  d: ELSE tv = e: e = 1  e
tval$(q) = LTRIM$(STR$(tv))
SELECT CASE q
CASE 1
IF ABS(ft$ = "l") <> tv THEN good = 0: EXIT FOR
CASE 2
IF ABS(gt$ = "v") <> tv THEN good = 0: EXIT FOR
CASE 3
IF ABS(ht$ = "n") <> tv THEN good = 0: EXIT FOR
CASE 4
IF ABS(ft$ = gt$) <> tv THEN good = 0: EXIT FOR
CASE 5
IF ABS(gt$ <> ht$) <> tv THEN good = 0: EXIT FOR
CASE 6
IF ABS(ft$ = "n") <> tv THEN good = 0: EXIT FOR
CASE 7
IF ABS(ht$ = "v") <> tv THEN good = 0: EXIT FOR
CASE 8
IF ABS(gt$ = "l") <> tv THEN good = 0: EXIT FOR
END SELECT
NEXT q
IF good THEN
PRINT seq$
FOR i = 1 TO 8
PRINT tval$(i);
NEXT
PRINT
PRINT "fgh"
PRINT ft$; gt$; ht$
PRINT
END IF
NEXT e1
NEXT d1
NEXT h
NEXT g
NEXT f
permute s$
LOOP UNTIL s$ = hld$

Posted by Charlie
on 20071009 11:44:14 