Enigmatic Code

Programming Enigma Puzzles

Enigma 442b: Oh yes I did! Oh no you didn’t!

From New Scientist #1592, 24th December 1987 [link]

After our successful pantomime production in which I played the leading lady, I gave my little costarring helpers some gifts from a big bag of different trinkets, and they each got a different number and none were left.

To make it fairer I gave each helper 10p for each gift that he didn’t get and deducted 40p for each gift that he did get, but that still gave each of them some 10p coins as well as some gifts. It cost me £12.60 in addition to the gifts.

What was the highest number of gifts received by any helper (that little fellow got less than 50p cash)?

What part was I playing?


This puzzle completes the archive of Enigma puzzles from 1987. There is now a complete archive from the start of Enigma in February 1979 to the end of 1987, and also from February 2000 to the final Enigma puzzle in December 2013. Making 1162 Enigma puzzles posted so far, which means there are about 626 left to post.

[enigma442b] [enigma442]

One response to “Enigma 442b: Oh yes I did! Oh no you didn’t!

  1. Jim Randell 6 April 2018 at 7:38 am

    126 ten-pence coins were given out. If there are k helpers who get a, b, c, d, … gifts, then in total N = a + b + c + d + … gifts are distributed.

    If a helper receives x gifts they also get N − 5x 10p coins.

    There are 126 coins in total, so:

    126 = kN − 5(a + b + c + d + …)
    126 = kN − 5N
    126 = (k − 5)N

    so: k > 5.

    Also each helper receives at least one coin, so:

    N − 5x ≥ 1
    x ≤ (N − 1) / 5

    This Python program runs in 158ms.

    Run: [ @repl.it ]

    from itertools import count
    from enigma import irange, printf
    # decompose t into k different increasing values between m and M
    def decompose(t, k, m=1, M=126, s=[]):
      if k == 1:
        if not(t < m or t > M):
          yield s + [t]
        k -= 1
        for n in irange(m, min(M, t - k * m)):
          yield from decompose(t - n, k, n + 1, M, s + [n])
    # minimum number of coins received
    M = 2 # "some 10p coins = at least 20p"
    # consider the number of helpers
    for k in count(6):
      (N, r) = divmod(126, k - 5)
      if N < 1: break
      if r != 0: continue
      # split the gifts amongst the k helpers
      for s in decompose(N, k, 1, (N - M) // 5):
        # calculate the number of 10p coins for each helper
        xs = list(N - 5 * x for x in s)
        if any(x < M for x in xs): continue
        # but the helper with the most gifts gets less than 5 coins
        if xs[-1] < 5: 
          printf("k={k} N={N} {s} {xs}")

    Solution: The helper who received the most gifts got 12. The role involves a leading lady with 7 “little co-stars”, so is probably Snow White.

    There are 7 helpers. Each of which receives a split of 63 available gifts. The actual split is (6, 7, 8, 9, 10, 11, 12), and the corresponding number of coins received is (33, 28, 23, 18, 13, 8, 3). So the helper who received 12 gifts also got three 10p coins (30p).

    In fact, in order to arrive at a single solution, we need to interpret “some 10p coins” as “at least two 10p coins”. Otherwise we can also get solutions with 6 helpers, the luckiest of which receives 25 gifts (of the 126 available) and one 10p coin.

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: