In planet Realmamber, the inhabitants are either Knights, who always speak truthfully; Liars, who always speak falsely; Knaves, who make statements that are alternately true and false, but in which order is unknown; or those few Rebels who do not abide by the planet's traditions.
How truthful a Rebel's statements are is unknown, except that they are not the same as those who are Knights, Liars, or Knaves. Thus, a rebel will never make just one or two statements; he will always make three or more.
A, B, C and D are four inhabitants of the planet, who are busy in a conversation when a visitor from a neighboring planet stops by and asks each of them their identity. They say:
Inhabitant A:
 My statements are not all truthful.
 We are overworked.
 We are all lucky to be here.
 We Realmamberians are favored by the gods.
Inhabitant B:
 I agree with A's third statement.
 Every time I see a visitor, I think maybe it is one of the gods, in disguise.
 I am doing more than my share of the work.
 My statements are all truthful.
Inhabitant C:
 My statements are all truthful.
 D's second statement is false.
 The gods do not visit us in disguise.
 We are all overworked.
Inhabitant D:
 C's first statement is truthful.
 B's third statement is truthful.
 My statements are all truthful.
 The gods frequently visit us in disguise.
Which one is the Knight, which one is the Liar, which one is the Knave, and which one is the Rebel?
FOR a1 = 1 TO 1
FOR a2 = 0 TO 1
FOR a3 = 0 TO 1
FOR a4 = 0 TO 1
IF a2 + a3 + a4 < 3 THEN
FOR b1 = a3 TO a3
FOR b2 = 0 TO 1
FOR b3 = 0 TO 1
FOR b4 = 0 TO 1
IF b4 = 0 OR b1 + b2 + b3 = 3 THEN
FOR c1 = 0 TO 1
FOR c2 = 0 TO 1
FOR c3 = 0 TO 1
FOR c4 = a2 TO a2 ' 0 TO 1
IF c1 = 0 OR c2 + c3 + c4 = 3 THEN
FOR d1 = c1 TO c1
FOR d2 = 1  c2 TO 1  c2
FOR d3 = 0 TO 1
FOR d4 = 1  c3 TO 1  c3
IF d3 = 0 OR d1 + d2 + d4 = 3 THEN
IF d2 = b3 THEN
kt = 0: li = 0: kv = 0: rb = 0
IF a1 + a2 + a3 + a4 = 4 THEN kt = kt + 1: ad = 1: ELSE ad = 0
IF b1 + b2 + b3 + b4 = 4 THEN kt = kt + 1: bd = 1: ELSE bd = 0
IF c1 + c2 + c3 + c4 = 4 THEN kt = kt + 1: cd = 1: ELSE cd = 0
IF d1 + d2 + d3 + d4 = 4 THEN kt = kt + 1: dd = 1: ELSE dd = 0
IF a1 + a2 + a3 + a4 = 0 THEN li = li + 1: ad = 1
IF b1 + b2 + b3 + b4 = 0 THEN li = li + 1: bd = 1
IF c1 + c2 + c3 + c4 = 0 THEN li = li + 1: cd = 1
IF d1 + d2 + d3 + d4 = 0 THEN li = li + 1: dd = 1
IF a1 + a2 = 1 AND a2 + a3 = 1 AND a3 + a4 = 1 THEN kv = kv + 1: ad = 1
IF b1 + b2 = 1 AND b2 + b3 = 1 AND b3 + b4 = 1 THEN kv = kv + 1: bd = 1
IF c1 + c2 = 1 AND c2 + c3 = 1 AND c3 + c4 = 1 THEN kv = kv + 1: cd = 1
IF d1 + d2 = 1 AND d2 + d3 = 1 AND d3 + d4 = 1 THEN kv = kv + 1: dd = 1
IF ad = 0 THEN rb = rb + 1
IF bd = 0 THEN rb = rb + 1
IF cd = 0 THEN rb = rb + 1
IF dd = 0 THEN rb = rb + 1
IF kt = 1 AND li = 1 AND kv = 1 AND rb = 1 THEN
PRINT a1; a2; a3; a4, b1; b2; b3; b4, c1; c2; c3; c4, d1; d2; d3; d4
solCt = solCt + 1
END IF
END IF
END IF
NEXT
NEXT
NEXT
NEXT
END IF
NEXT
NEXT
NEXT
NEXT
END IF
NEXT
NEXT
NEXT
NEXT
END IF
NEXT
NEXT
NEXT
NEXT
PRINT solCt
finds
1 0 1 1 1 1 1 1 0 0 0 0 0 1 0 1
which represent the truth value of the statements in order with 1=true and 0=false.
That means A, B, C and D are Rebel, Knight, Liar and Knave in that order.

Posted by Charlie
on 20100105 12:56:38 