Enigmatic Code

Programming Enigma Puzzles

Tantalizer 490: Diplomatic niceties

From New Scientist #1041, 3rd March 1977 [link]

Before assuming office as governor of Coconut Island, Sir Donald Duck briefed himself as best he could. There were, he discovered, four chiefs called Fe, Fi, Fo and Fum. The mark of chiefly rank was a turkey feather, red or green at will. The senior chief wore an old pair of Wellington boots and the others went barefoot. Fe always spoke the truth, Fi never, Fo pleased himself and Fum spoke the truth when and only when wearing a green feather.

Knowing no more than this, Sir Donald landed with pomp and found the four chiefs awaiting him. He shook hands all round and inquired, “What is the name of the senior chief?” One chief replied “Fe”, another “not Fum” and a third “Fo”. Sir Donald did not hear the fourth reply but it did not matter, since, being a Balliol man and so very clever, he worked out the name of the senior chief without it.

What was the name of the senior chief?

[tantalizer490]

Advertisements

One response to “Tantalizer 490: Diplomatic niceties

  1. Jim Randell 16 February 2017 at 8:32 am

    As far as Sir Donald is concerned he met four chiefs, each of which was wearing a red or green feather, and one of which was wearing wellies. He doesn’t know which of the four names belongs to which chief, but from the responses of the first three he is able to deduce the name of the senior chief (who is the one wearing the wellies).

    This Python program looks at each possible scenario for the assignments of the feathers and the wellies to the four chiefs, and then looks possible assignments of names to the chiefs such that the responses of the first three chiefs is consistent with the described behaviour. If the responses are consistent we record the name of the senior chief. If at the end of considering the possible assignments of names to chiefs there is only one possibility for the senior chief, then this is a possible scenario that Sir Donald found himself in.

    The program runs in 44ms.

    from itertools import product, permutations
    from enigma import printf
    
    # the chiefs
    chiefs = (0, 1, 2, 3)
    
    # choose a scenario
    for wellies in chiefs:
      for feather in product('RG', repeat=4):
    
        # accumulate possible names for the senior chief
        r = set()
    
        # now consider assignments of names to the chiefs
        for name in permutations(('Fe', 'Fi', 'Fo', 'Fum')):
    
          # check the statements
          def check(chief, statement):
            # Fe always speaks the truth
            if chief == 'Fe':
              return (statement == True)
            # Fi never speaks the truth
            if chief == 'Fi':
              return (statement == False)
            # Fo pleased himself
            if chief == 'Fo':
              return True
            # Fum speaks the truth iff he has a green feather
            if chief == 'Fum':
              return (statement == (feather[name.index('Fum')] == 'G'))
    
          # first chief says Fe is the senior chief
          if not check(name[0], name[wellies] == 'Fe'): continue
    
          # second chief says "not Fum" is the senior chief
          if not check(name[1], name[wellies] != 'Fum'): continue
    
          # third chief says Fo is the senior chief
          if not check(name[2], name[wellies] == 'Fo'): continue
    
          r.add(name[wellies])
    
        # look for cases when there is only one possibility
        if len(r) == 1:
          s = tuple(r)[0]
          printf("senior chief = {s} [feather = {feather}]")
    

    Solution: The name of the senior chief is Fi.

    It turns out there is only one situation where Sir Donald would be able to deduce the name of the senior chief.

    That is, if the three chiefs whose replies he heard are all wearing red feathers, and the fourth chief is wearing the wellies (we don’t make a judgement on his reply, so it doesn’t matter what colour feather he is wearing).

    In this case, in order for the replies heard to be consistent, the three chiefs are either (Fo, Fe, Fum) or (Fum, Fe, Fo), and the fourth (and senior) chief is Fi.

    Consider the first order:

    Chief 1 = Fo (pleases himself)
    Chief 2 = Fe (always speaks the truth)
    Chief 3 = Fum (lies – as he is wearing a red feather)
    Chief 4 = Fi (wears the wellies, and is the senior chief)

    Chief 1 says the senior chief is Fe. This is a false statement. But as he is Fo this is consistent.
    Chief 2 says the senior chief is not Fum. This is a true statement. He is Fe, so this is also consistent.
    Chief 3 says the senior chief is Fo. This is a false statement. He is Fum, wearing a red feather, so lies.

    In the second case Chief 1 is Fum, and Chief 3 is Fo, and they both can still consistently utter falsehoods.

    In either case the senior chief is Fi, so this is the deduction that Sir Donald makes, and is the answer to the puzzle.

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: