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):
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$)
s$ = "dddeeee"
hld$ = s$
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
IF ABS(ft$ = "l") <> tv THEN good = 0: EXIT FOR
IF ABS(gt$ = "v") <> tv THEN good = 0: EXIT FOR
IF ABS(ht$ = "n") <> tv THEN good = 0: EXIT FOR
IF ABS(ft$ = gt$) <> tv THEN good = 0: EXIT FOR
IF ABS(gt$ <> ht$) <> tv THEN good = 0: EXIT FOR
IF ABS(ft$ = "n") <> tv THEN good = 0: EXIT FOR
IF ABS(ht$ = "v") <> tv THEN good = 0: EXIT FOR
IF ABS(gt$ = "l") <> tv THEN good = 0: EXIT FOR
IF good THEN
FOR i = 1 TO 8
PRINT ft$; gt$; ht$
LOOP UNTIL s$ = hld$
Posted by Charlie
on 2007-10-09 11:44:14