Enigmatic Code

Programming Enigma Puzzles

Enigma 1259: Keeping order

From New Scientist #2415, 4th October 2003 [link]

As part of an exam the letters A to F were written down in some order and briefly shown to the candidates, who then tried to memorise the order. Their individual recollections were:

candidate 1: BCDAEF;
candidate 2: DAEFBC;
candidate 3: ABEFDC;
candidate 4: BCFDEA;
candidate 5: AEBDFC;
candidate 6: CFEABD;
candidate 7: DCAEFB.

Then the written exam consisted of a list of questions: for each pair of the letters the candidates were asked which came first. So, for example, one of the questions was “Which came first, A or B?” and another question was “Which came first, A or C?” and so on.

The candidates based their answers on their own individual recollections of the order and, as a consequence, each candidate got a different, even number of the questions right.

What was the correct order?


One response to “Enigma 1259: Keeping order

  1. Jim Randell 31 January 2015 at 9:01 am

    It’s easy enough to consider all the possible permutations of the letters.

    This Python program runs in 204ms.

    from itertools import permutations, combinations
    from enigma import printf
    # candidate's recollections of the order
    rs = (
    # count the number of correct ordered pairs
    def count(r, s):
      return sum(1 for (a, b) in combinations(s, 2) if r.index(a) < r.index(b))
    # consider possible correct orderings
    for s in permutations('ABCDEF'):
      # count how many pairs are right for each candidate
      t = set(count(r, s) for r in rs)
      # the answers should be distinct, and all even
      if len(t) == 7 and all(x % 2 == 0 for x in t):
        printf("{s} => {t}")

    Solution: The correct order was DAEFCB.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: