Enigmatic Code

Programming Enigma Puzzles

Enigma 294: The Great and the Good

From New Scientist #1442, 7th February 1985 [link]

There are five possible chairman for the new Committee on Honary Degrees in Ancient Universities. All are on the secret list of the Great and the Good, where each has a secret score for Greatness and another for Goodness. All their scores are different but the exact figures have not yet been leaked to the newspapers.

Having seen the whole book, however, I can reveal that Sir Anthony Absolute is better than anyone greater than Dame Barbara Beveridge. Sir Charles Cumference is greater than all and only those better than Lady Dunstable. Lord Enterprise is less good than all and only those greater than Absolute. The least good of them is not also the least great.

The job, it has been decided, needs a good chairman. So please rank them in order of goodness.

[enigma294]

Advertisements

One response to “Enigma 294: The Great and the Good

  1. Jim Randell 12 July 2015 at 8:04 am

    This Python program checks all permutations in 76ms.

    from itertools import permutations, product
    from enigma import irange, printf
    
    # X implies Y
    def implies(X, Y): return not(X) or Y
    
    # X if and only if Y
    def iff(X, Y): return X == Y
    
    # label the candidates
    candidates = (A, B, C, D, E) = irange(0, 4)
    
    # choose a score (1 to 5) for each quality
    for (great, good) in product(permutations(irange(1, 5)), repeat=2):
    
      # A is better than anyone greater than B
      if not all(implies(great[x] > great[B], good[A] > good[x]) for x in candidates): continue
    
      # C is greater than all (and only those) better than D
      if not all(iff(good[x] > good[D], great[C] > great[x]) for x in candidates): continue
    
      # E is less good than all (and only those) greater than A
      if not all(iff(great[x] > great[A], good[E] < good[x]) for x in candidates): continue
    
      # the least good is not also the least great
      if great[good.index(1)] == 1: continue
    
      # output the orders (highest scored to lowest scored)
      fmt = lambda g: ' '.join(x[1] for x in sorted(zip(g, 'ABCDE'), reverse=True, key=lambda x: x[0]))
      printf("good = {good}, great = {great}", good=fmt(good), great=fmt(great))
    

    Solution: The candidates ranked in order of “goodness” (highest scoring first) are: Dunstable, Beveridge, Enterprise, Cumference, Absolute.

    Ranked in order of “greatness” (highest scoring first): Beveridge, Dunstable, Absolute, Enterprise, Cumference.

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: