All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Logic > Liars and Knights
Twins (Posted on 2009-01-07) Difficulty: 2 of 5
Alex, Bert, Carl, and Dave are all brothers, with two of them being twins. At least one of them is a knight and makes all true statements. At least one of them is a liar and makes all false statements. And at least one of them is a knave and makes alternating true and false statements. The two which are the same type are the twins. From the statements below, determine who the twins are.

Alex:
1) Bert is one of the twins.
2) Carl is a liar.

Bert:
1) Carl is one of the twins.
2) Alex is a knight.

Carl:
1) I am not one of the twins.

See The Solution Submitted by Brian Smith    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 2 of 6 |


The program below results in the output "vlkl" indicating A, B, C and D are respectively knave, liar, knight, liar. Therefore liars Bert and Dave are the twins.


The program tries successively 2 knights, a liar and a knave; a knight, 2 liars and a knave; and a knight, a liar and 2 knaves; in each case permuting among A, B, C and D, and in the case of any knave allowing for either the first or the second statement to be the true one. If the resulting truth values are consistent, the sequence of types is displayed.

DECLARE SUB try (s$)
DECLARE SUB permute (a$)
try "kklv"
try "kllv"
try "klvv"

END


SUB try (s$)
 DIM v(2), q(5)
 h$ = s$
 s1$ = s$
 IF RIGHT$(h$, 2) = "vv" THEN noV = 2:  ELSE noV = 1
 DO
   IF noV = 1 THEN
     FOR v1 = 1 TO 2
       GOSUB tryOne
     NEXT v1
   ELSE
     FOR v1 = 1 TO 2
       FOR v2 = 1 TO 2
         GOSUB tryOne
       NEXT v2
     NEXT v1
   END IF
   permute s1$
 LOOP UNTIL s1$ = h$

 EXIT SUB

tryOne:
 vCt = 0
 v(1) = v1: v(2) = v2
 SELECT CASE MID$(s1$, 1, 1)
   CASE "k"
    q(1) = 1: q(2) = 1
   CASE "l"
    q(1) = 0: q(2) = 0
   CASE "v"
    vCt = vCt + 1
    IF v(vCt) = 1 THEN
      q(1) = 1: q(2) = 0
    ELSE
      q(1) = 0: q(2) = 1
    END IF
 END SELECT
 SELECT CASE MID$(s1$, 2, 1)
   CASE "k"
    q(3) = 1: q(4) = 1
   CASE "l"
    q(3) = 0: q(4) = 0
   CASE "v"
    vCt = vCt + 1
    IF v(vCt) = 1 THEN
      q(3) = 1: q(4) = 0
    ELSE
      q(3) = 0: q(4) = 1
    END IF
 END SELECT
 SELECT CASE MID$(s1$, 3, 1)
   CASE "k"
    q(5) = 1
   CASE "l"
    q(5) = 0
   CASE "v"
    vCt = vCt + 1
    IF v(vCt) = 1 THEN
      q(5) = 1
    ELSE
      q(5) = 0
    END IF
 END SELECT
 good = 1
 tw$ = "    "
 FOR i = 1 TO 4
  FOR j = 1 TO 4
   IF i <> j THEN
     IF MID$(s1$, i, 1) = MID$(s1$, j, 1) THEN
       MID$(tw$, i, 1) = "t"
       MID$(tw$, j, 1) = "t"
     END IF
   END IF
  NEXT
 NEXT
 IF q(1) = 1 AND MID$(tw$, 2, 1) = " " OR q(1) = 0 AND MID$(tw$, 2, 1) <> " " THEN good = 0
 IF q(2) = 1 AND MID$(s1$, 3, 1) <> "l" OR q(2) = 0 AND MID$(s1$, 3, 1) = "l" THEN good = 0
 IF q(3) = 1 AND MID$(tw$, 3, 1) = " " OR q(3) = 0 AND MID$(tw$, 3, 1) <> " " THEN good = 0
 IF q(4) = 1 AND MID$(s1$, 1, 1) <> "k" OR q(4) = 0 AND MID$(s1$, 1, 1) = "k" THEN good = 0
 IF q(5) = 1 AND MID$(tw$, 3, 1) <> " " OR q(5) = 0 AND MID$(tw$, 3, 1) = " " THEN good = 0
 IF good THEN
   PRINT s1$
 END IF
RETURN


END SUB

 


  Posted by Charlie on 2009-01-07 16:32:03
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (2)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information