There is a land where every inhabitant is either a day-knight or a night-knight. Day-knights tell the truth in the day and lie at night. Night-knights lie in the day and tell the truth at night.
Members of the Smith family are day-knights and, members of the Jones family are night-knights.
Four inhabitants Art, Barry, Cole and Dan approach a visitor to the island. It is known that precisely two of them are members of the Jones family and the remaining two are members of the Smith family.
They say:
Art: Barry’s last name is Smith.
Barry: Cole belongs to the Jones family.
Cole: Art and Dan are from different families.
Dan: Art and Barry are from the same family.
What are the surnames of the three inhabitants? Is it day or night?
DECLARE SUB permute (a$)
CLS
a$ = "ssjj": h$ = a$ ' for Art Barry Cole and Dan respectively
' s=smith-day; j=jones-night
DO
FOR day = 0 TO 1
truth$ = MID$("sj", 2 - day, 1)
good = 1
IF (MID$(a$, 1, 1) = truth$) <> (MID$(a$, 2, 1) = "s") THEN good = 0
IF (MID$(a$, 2, 1) = truth$) <> (MID$(a$, 3, 1) = "j") THEN good = 0
IF (MID$(a$, 3, 1) = truth$) <> (MID$(a$, 1, 1) <> MID$(a$, 4, 1)) THEN good = 0
IF (MID$(a$, 4, 1) = truth$) <> (MID$(a$, 1, 1) = MID$(a$, 2, 1)) THEN good = 0
IF good THEN PRINT MID$("dn", 2 - day, 1); " "; a$
NEXT
permute a$
LOOP UNTIL a$ = h$
finds
d jjss
meaning it is daytime and Art and Barry are Joneses and Cole and Dan are Smiths.
|
Posted by Charlie
on 2014-03-03 13:17:00 |