Enigmatic Code

Programming Enigma Puzzles

Tantalizer 493: Prize guys

From New Scientist #1044, 24th March 1977 [link]

I met Tom on his way back from the pet show looking pleased with himself. “Prize for my budgie, prize for my cat, prize for my dog”, he explained, “How did Dick and Harry do?”

“Don’t you know?” I asked.

“Not a thing.”

“They too got a prize each for each of a budgie, cat and dog. So you scooped all those nine prizes between you — no ties, incidentally. Dick’s lowest prize was for his budgie.”

“Oho,” exclaimed Tom after reflection, “so Harry did better with his cat than with his dog.”

He then listed all nine prizes correctly. Can you?

[tantalizer493]

Advertisements

One response to “Tantalizer 493: Prize guys

  1. Jim Randell 18 January 2017 at 8:21 am

    This Python program examines all the possibilities in 44ms.

    from itertools import product, permutations
    from collections import defaultdict
    from enigma import printf
    
    # labels for Tom, Dick, Harry
    (T, D, H) = (0, 1, 2)
    
    # consider possible assignments of prizes (1st, 2nd, 3rd)
    # in the categories, record results by Tom's prizes
    r = defaultdict(list)
    for (b, c, d) in product(permutations((1, 2, 3)), repeat=3):
    
      # "Dick's lowest prize was for his budgie"
      if not(b[D] > c[D] and b[D] > d[D]): continue
    
      # record the results
      r[(b[T], c[T], d[T])].append((b, c, d))
    
    # consider the results
    for (k, vs) in r.items():
    
      # Tom's result => Harry did better with his cat than his dog
      if not all(c[H] < d[H] for (b, c, d) in vs): continue
    
      # and Tom knows the full result
      if len(vs) == 1:
        (b, c, d) = vs[0]
        for (i, name) in zip((T, D, H), ('Tom', 'Dick', 'Harry')):
          printf("{name}: budgie={b}, cat={c}, dog={d}", b=b[i], c=c[i], d=d[i])
        printf()
    

    Solution: The prizes are as follows:

    Budgie: 1st = Harry, 2nd = Dick, 3rd = Tom;
    Cat: 1st = Dick, 2nd = Harry, 3rd = Tom;
    Dog: 1st = Dick, 2nd = Tom, 3rd = Harry.

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: