Enigmatic Code

Programming Enigma Puzzles

Enigma 282: Beer bounty

From New Scientist #1429, 8th November 1984 [link]

Apart from providing the beer at my birthday party, I decided to encourage the abstemious by paying every guest a bounty of 10p for every pint drunk by someone else minus 20p for every pint he drank himself. I can’t remember all the details, but I do know that I paid out £9 in bounty altogether. Each guest drank a different odd number of pints, and everyone received some bounty money except David, who consumed so much beer (no one else’s consumption was within 3 pints of his) that he got exactly nothing in bounty.

From that information you can probably work out just how much each guest drank. If you do, please let me know.



One response to “Enigma 282: Beer bounty

  1. Jim Randell 21 May 2015 at 8:08 am

    Using units of 10p, if we have n people who drink p_1, p_2, …, p_n pints (lets say in descending order).

    Then, if t is the total number of pints drunk:

    t = p_1 + p_2 + … + p_n

    And the bounty for the k-th person is:

    (t – p_k) – 2 p_k = t – 3 p_k

    David, the person who drinks the most, gets zero bounty, so:

    t – 3 p_1 = 0
    t = 3 p_1

    Also the total of all the bounties is 90 units:

    (t – 3 p_1) + (t – 3 p_2) + … + (t – 3 p_n) = 90
    n t – 3(p_1 + p_2 + … + p_n) = 90
    (n – 3) t = 90

    So we can consider the divisors of 90.

    This Python3 program runs in 54ms.

    from enigma import divisor_pairs, irange, printf
    # decompose <t> into <n> different odd numbers, less than <m>
    def decompose(t, n, m, ps):
      if n == 1:
        if not(t > m):
          yield ps + [t]
        for p in irange(m, 3, step=-2):
          yield from decompose(t - p, n - 1, p - 2, ps + [p])
    # possible values for n and t, st (n - 3)t = 90
    for (n, t) in divisor_pairs(90):
      n += 3
      # number of pints David drinks
      (p1, r) = divmod(t, 3)
      if r > 0: continue
      # each number of pints is odd
      if p1 % 2 == 0: continue
      # decompose the remaining pints into an increasing odd sequence
      for ps in decompose(t - p1, n - 1, p1 - 4, [p1]):
        # compute the bounties
        bs = list(t - 3 * p for p in ps)
        printf("n={n} t={t} ps={ps} bs={bs}")

    Solution: The guests drank (in decreasing numbers of pints): 15 pints (David), 11 pints, 9 pints, 7 pints, 3 pints.

    So, a total of 45 pints were consumed by the 5 guests. (Quite a boozy party).

    The corresponding bounties are: 0p (for David), £1.20, £1.80, £2.40, £3.60.

    I’m not quite sure why the setter wrote “from that information you can probably work out just how much each guest drank” – maybe he had had a couple of pints too many himself.

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

%d bloggers like this: