A very special island is inhabited only by knights and liars. Knights always tell the truth, and liars always lie.
Nine inhabitants of the island: Mel, Bart, Sue, Betty, Rex, Zeke, Sally, Zoey and Homer are busy at a conversation. A visitor from a neighboring island stops by and asks each of the nine inhabitants their respective identities. They say:
 Mel: "Only a liar would say that Sally is a liar."
 Bart: "Rex is a liar."
 Sue: "Mel and Homer are liars."
 Betty: "I know that I am a knight and Sally is a liar."
 Rex : "Betty and I are both knights."
 Zeke: "At least one of the following is true: that Sally is a knight or that Sue is a knight."
 Sally:"It's false that Betty is a liar."
 Zoey: "It's not the case that Sue is a liar."
 Homer: "Betty is a liar or Zeke is a liar."
Determine the type of each of the inhabitants from the abovementioned statements.
Bart and Homer are the only knights; the rest are liars.
FOR k1 = 0 TO 1
FOR k2 = 0 TO 1
FOR k3 = 0 TO 1
FOR k4 = 0 TO 1
FOR k5 = 0 TO 1
FOR k6 = 0 TO 1
FOR k7 = 0 TO 1
FOR k8 = 0 TO 1
FOR k9 = 0 TO 1
IF k1 = k7 THEN
IF k2 = 1  k5 THEN
IF k3 = ABS(k1 = 0 AND k9 = 0) THEN
IF k4 = 0 OR k7 = 0 THEN
IF k5 = 0 OR k4 = 1 THEN
IF k6 = ABS(k7 = 1 OR k3 = 1) THEN
IF k7 = k4 THEN
IF k8 = k3 THEN
IF k9 = ABS(k4 = 0 OR k6 = 0) THEN
PRINT k1; k2; k3; k4; k5; k6; k7; k8; k9
END IF
END IF
END IF
END IF
END IF
END IF
END IF
END IF
END IF
NEXT
NEXT
NEXT
NEXT
NEXT
NEXT
NEXT
NEXT
NEXT
lists the types in order of appearance, with 0=liar and 1=knight:
0 1 0 0 0 0 0 0 1

Posted by Charlie
on 20100206 14:09:13 