Enigmatic Code

Programming Enigma Puzzles

Enigma 99: Harem scarem

From New Scientist #1243, 5th March 1981 [link]

The six wives of Sheikh Inbed the Terrible are in something of a tizz. They have just heard that they are to be reshuffled in their present ranking. At least two will rise, at least two fall; and no-one will have her same place after the sheikh-up.

Each has issued a prediction. “Bathsheba and I will both be demoted,” predicts Armenia. “Euterpe will be placed above both Delilah and Fatima,” Bathsheba opines. Casbah, the present No. 3 wife, expects that Delilah will outrank Fatima. Delilah predicts a rise of exactly one place for herself. Euterpe’s guess is that she herself will go down and that Casbah will outrank Armenia. “I shall fall and Casbah will rise,” predicts Fatima.

Sheikh Inbed would have you know that those about to rise are right and those about to fall wrong.

Can you list the ladies in order of rank (No. 1 first) both before and after?

[enigma99]

Advertisements

3 responses to “Enigma 99: Harem scarem

  1. Jim Randell 16 June 2013 at 8:40 am

    The following Python program runs in 593ms.

    from itertools import permutations
    from enigma import printf
    
    (A, B, C, D, E, F) = names = list('ABCDEF')
    
    X = '?'
    before = { A: X, B: X, C: 3, D: X, E: X, F: X }
    for (before[A], before[B], before[D], before[E], before[F]) in permutations((1, 2, 4, 5, 6)):
      # for the after state
      for s in permutations((1, 2, 3, 4, 5, 6)):
        after = dict(zip(names, s))
        # no-one will keep their position
        if any(before[n] == after[n] for n in names): continue
        # at least two will rise
        if sum(1 for n in names if after[n] < before[n]) < 2: continue
        # and at least two will fall
        if sum(1 for n in names if after[n] > before[n]) < 2: continue
    
        # evaluate the statements
        ss = {
          # A: "A and B will be demoted"
          A: (after[A] > before[A] and after[B] > before[B]),
          # B: "E will be placed above D and F"
          B: (after[E] < after[D] and after[E] < after[F]),
          # C: "D will outrank F"
          C: (after[D] < after[F]),
          # D: "D will rise 1 place"
          D: (after[D] + 1 == before[D]),
          # E: "E will go down, and C will outrank A"
          E: (after[E] > before[E] and after[C] < after[A]),
          # F: "F will fall, C will rise"
          F: (after[F] > before[F] and after[C] < before[C])
        }
    
        # those that rise are right, those that fall are wrong
        if not all((after[n] < before[n]) == ss[n] for n in names): continue
    
        # output a solution
        printf("before: {b}", b=' '.join(sorted(before.keys(), key=lambda x: before[x])))
        printf("after : {a}", a=' '.join(sorted(after.keys(), key=lambda x: after[x])))
        print()
    

    Solution: The ranking before the reshuffle is: Euterpe (1st), Fatima (2nd), Casbah (3rd), Armenia (4th), Delilah (5th), Bathsheba (6th). After the reshuffle the ranking is: Bathsheba (1st), Euterpe (2nd), Fatima (3rd), Delilah (4th), Armenia (5th), Casbah (6th).

    I have marked this puzzle as flawed, as I think it is reasonable that given the “before” rankings each of the predictions should be possible. But A predicts that both A and B will be demoted. However the only possible solution requires B to be in last place in the “before” rankings, making it impossible that B can be demoted.

    It’s a bit worrying that three flawed Enigmas were published successively (97, 98 and 99).

    • Jim Olson 16 June 2013 at 6:28 pm

      The standard convention of logical construction would direct A is falling and therefore wrong in her prediction. If she were correct then both she and B would have to be demoted. A contradiction in what the sheikh said. But under the standard construction of a conjunction being wrong only one must be wrong. Therefore to adhere to what the sheikh said A falls and B rises.

      • Jim Randell 5 August 2013 at 12:33 pm

        I don’t think you understand my objection to the problem. It is not that A’s prediction was “half-right”, it’s that given the “before” ordering (which is presumably known to the wives when they make their predictions – it’s certainly not stated that it isn’t), the prediction that A makes is never satisfiable as B cannot be demoted beyond last place.

        The astute puzzler should be able to use all the information given to narrow down the solution space, but if you do that here you eliminate “before” orderings where B is in 6th place, and find no solutions.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: