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

Home > Logic > Liars and Knights
Another Race (Posted on 2003-12-15) Difficulty: 3 of 5
When I went to the race track in Racing Town, a town made up only of Knights which always tell the truth, Knaves which tell truths and lies in an alternating pattern, and Liars which always lie, a race between 6 citizens of that town had just finished.

I went to the 6 citizens and asked each of them the order that all 6 finished. They all gave me different responses, each thinking themselves as winning, displayed here left to right as first to last.

A: A C D E B F
B: B D F E C A
C: C D E F A B
D: D E F B A C
E: E B A D F C
F: F C B A E D

From what they said, I was able to figure out what the correct order was. What is it?

See The Solution Submitted by Gamer    
Rating: 3.3636 (11 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
... and the computer way. | Comment 4 of 9 |
The answer is also provided by running:
DECLARE FUNCTION eval$ (s1$, s2$)
DATA ACDEBF
DATA BDFECA
DATA CDEFAB
DATA DEFBAC
DATA EBADFC
DATA FCBAED
CLS
FOR i = 1 TO 6
 READ order$(i)
NEXT

FOR winner = 1 TO 6
 good = 1
 FOR speaker = 1 TO 6 ' evaluate if winner is knight
   id$ = eval$(order$(speaker), order$(winner))
   IF id$ = "-" THEN good = 0: EXIT FOR
 NEXT speaker
 IF good THEN PRINT order$(winner)
 ' evaluate if winner is knave
 var$ = MID$(order$(winner), 2, 1) + MID$(order$(winner), 4, 1) + MID$(order$(winner), 6, 1)
 winsays$ = order$(winner)
 FOR perm = 1 TO 2
  var$ = MID$(var$, 2) + LEFT$(var$, 1)
  FOR psn = 1 TO 3
   MID$(winsays$, 2 * psn, 1) = MID$(var$, psn, 1)
  NEXT psn
  good = 1
  FOR speaker = 1 TO 6
    id$ = eval$(order$(speaker), winsays$)
    IF id$ = "-" THEN good = 0: EXIT FOR
  NEXT speaker
  IF good THEN PRINT winsays$
 NEXT perm
NEXT winner

FUNCTION eval$ (s1$, s2$)
  e$ = "-": evenCt = 0: oddCt = 0
  FOR i = 1 TO 3
    IF MID$(s1$, 2 * i - 1, 1) = MID$(s2$, 2 * i - 1, 1) THEN oddCt = oddCt + 1
    IF MID$(s1$, 2 * i, 1) = MID$(s2$, 2 * i, 1) THEN evenCt = evenCt + 1
  NEXT i
  IF evenCt = 3 THEN
    IF oddCt = 3 THEN
     e$ = "knight"
    ELSEIF oddCt = 0 THEN
     e$ = "knave"
    END IF
  ELSEIF evenCt = 0 THEN
    IF oddCt = 3 THEN
      e$ = "knave"
    ELSEIF oddCt = 0 THEN
      e$ = "liar"
    END IF
  END IF
  eval$ = e$
END FUNCTION


  Posted by Charlie on 2003-12-15 09:28:25
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 (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

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