Enigmatic Code

Programming Enigma Puzzles

Enigma 74: Superdads

From New Scientist #1217, 4th September 1980 [link]

The school sports ended with a “Fathers’ event” or, to be exact, three of them. A “Fathers’ hop” was followed by a “Fathers’ skip” and a “Fathers’ jump”. Most dads were strangely absent when the call for volunteers went up but the headmistress managed to bag four who were new to the school.

They went sheepishly to the slaughter. Amble did better than Dimwit in the Hop, Bumble won the silver star in the Skip, and did better than Crumble in the Jump. Crumble collected one silver star and Dimwit one gold one. In fact, no one gained more than one gold star or more than one silver or more than one bronze. There were no ties and the order in the Hop was the precise reverse of that in the Jump.

When the stars were totted up, who was Superdad and who was 2nd, 3rd and 4th?

[enigma74]

One response to “Enigma 74: Superdads

  1. Jim Randell 24 March 2013 at 9:23 pm

    This Python program runs in 40ms.

    from itertools import permutations
    from collections import defaultdict
    from enigma import printf
    
    # labels for A, B, C, D
    (A, B, C, D) = (0, 1, 2, 3)
    
    # consider possible orders for the hop
    for h in permutations((1, 2, 3, 4)):
      # A was placed before D in the hop
      if not(h[A] < h[D]): continue
      # orders for the jump are the reverse of the hop
      j = tuple(5 - h[x] for x in (A, B, C, D))
      # B was placed before C in the jump
      if not(j[B] < j[C]): continue
      # in the skip B was placed 2nd
      s = [0, 2, 0, 0]
      for (s[0], s[2], s[3]) in permutations((1, 3, 4)):
        # count up the placements for each dad (using indices 1-4)
        p = list([0, 0, 0, 0, 0] for i in (A, B, C, D))
        for x in (h, s, j):
          for i in (A, B, C, D):
            p[i][x[i]] += 1
        # C got 1 2nd place and D got 1 1st place
        if not(p[C][2] == 1 and p[D][1] == 1): continue
        # no-one got more than 1 1st, 2nd or 3rd place
        if any(any(c > 1 for c in x[1:4]) for x in p): continue
    
        # output the solution(s)
        order = lambda x: ' '.join(t[1] for t in sorted(zip(x, 'ABCD')))
        print("   1 2 3 4")
        printf("H: {h}", h=order(h))
        printf("S: {s}", s=order(s))
        printf("J: {j}", j=order(j))
        print('final order:', ' '.join(t[1] for t in sorted(zip(p, 'ABCD'), reverse=True)))
        print('')
    

    Solution: Overall D came first, B came second, A came third and C came fourth.

    There are two different ways to achieve the solution.

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: