Enigmatic Code

Programming Enigma Puzzles

Tantalizer 407: Late knight extra

From New Scientist #957, 10th July 1975 [link]

Of the King’s four champions, Sir Albus was the bravest, Sir Bruce, astride Geronimo, the strongest, Sir Caspar, in his purple helm, the proudest and Sir Daniel, with his lilac banner, the craftiest. All were mounted on fine steeds, the knight with the silver shield on Evangeline, he with the orange plume on Furiosus and he with the silver helm on Hercules.

Resplendent too were the hues of their accoutrements. One wore an orange helm and purple shield. One displayed a silver plume and orange shield. One boasted a lilac shield and silver banner. One rejoiced in a lilac helm and purple banner. Sir Caspar’s brother flaunted a lilac plume and orange banner.

“What noble knight is that”, inquired the Queen, “whose purple plume the fitful breezes toss?”.

Can you oblige Her Majesty?

[tantalizer407]

One response to “Tantalizer 407: Late knight extra

  1. Jim Randell 8 April 2020 at 8:27 am

    There are potentially (4!)^5 = 7,962,624 possibilities, but each condition only involves 1 or 2 attributes of any knight, so by testing conditions as soon as we can we get a reasonable run time.

    The following Python program runs in 95ms.

    Run: [ @repl.it ]

    from itertools import permutations
    from enigma import printf
    
    # labels
    knights = "ABCD"
    mounts = "EFGH"
    colours = ("purple", "lilac", "silver", "orange")
    
    # map knights to target type
    def make_map(tgt):
      for p in permutations(tgt):
        yield dict(zip(knights, p))
    
    # map knights to mounts
    for mount in make_map(mounts):
    
      # "Sir Bruce, astride Geronimo"
      if not(mount['B'] == 'G'): continue
    
      # map knights to helm
      for helm in make_map(colours):
    
        # "Caspar, in his purple helm"
        if not(helm['C'] == 'purple'): continue
    
        # "he with the silver helm on Hercules"
        if not any(helm[x] == 'silver' and mount[x] == 'H' for x in knights): continue
    
        # map knights to banner
        for banner in make_map(colours):
    
          # "Daniel, with his lilac banner"
          if not(banner['D'] == 'lilac'): continue
    
          # "One rejoiced in a lilac helm and purple banner"
          if not any(helm[x] == 'lilac' and banner[x] == 'purple' for x in knights): continue
    
          # map knights to shield
          for shield in make_map(colours):
    
            # "the knight with the silver shield on Evangeline"
            if not any(shield[x] == "silver" and mount[x] == 'E' for x in knights): continue
    
            # "One wore an orange helm and purple shield"
            if not any(helm[x] == "orange" and shield[x] == "purple" for x in knights): continue
    
            # "One boasted a lilac shield and silver banner"
            if not any(shield[x] == "lilac" and banner[x] == "silver" for x in knights): continue
    
            # map knights to plume
            for plume in make_map(colours):
    
              # "he with the orange plume on Furiosus"
              if not any(plume[x] == "orange" and mount[x] == "F" for x in knights): continue
    
              # "One displayed a silver plume and orange shield"
              if not any(plume[x] == "silver" and shield[x] == "orange" for x in knights): continue
    
              # "Caspar's brother flaunted a lilac plume and orange banner"
              if not any(x != 'C' and plume[x] == "lilac" and banner[x] == "orange" for x in knights): continue
    
              # output solution
              for x in knights:
                (m, b, h, p, s) = (d[x] for d in (mount, banner, helm, plume, shield))
                printf("{x}: mount={m}, banner={b}, helm={h}, plume={p}, shield={s}")
              printf()
    

    Solution: Sir Albus has the purple plume.

    The information provided is enough to fully describe each Knight:

    Albus: mount=Evangeline, banner=purple, helm=lilac, plume=purple, shield=silver
    Bruce: mount=Geronimo, banner=orange, helm=orange, plume=lilac, shield=purple
    Caspar: mount=Furiosus, banner=silver, helm=purple, plume=orange, shield=lilac
    Daniel: mount=Hercules, banner=lilac, helm=silver, plume=silver, shield=orange

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: