# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1567: My round

From New Scientist #2730, 17th October 2009 [link]

A group of friends and I each had a half-pint of shandy (beer mixed with lemonade), but the proportion of lemonade to beer varied from glass to glass. Overall, I had a certain whole-number percentage of the lemonade used in the round of drinks, and a certain whole-number percentage of the beer. The percentage of beer was 5 more than that of the lemonade.

If I now told you the actual percentages it would be possible to work out how many of us there were in the group.

Knowing that, if instead I now told you how many of us there were, you could work out the percentages.

How many of us were there, and what percentage of the lemonade did I have?

[enigma1567]

### 4 responses to “Enigma 1567: My round”

1. Jim Randell 21 February 2012 at 7:44 pm

The following Python program runs in 37ms.

```from itertools import count
from collections import defaultdict

# if I have 50%L and 55%B then there's only 50%L and 45%B left -
# not enough to make one drink, so I must have <50%L

d = defaultdict(list)
for L in range(1, 50):
B = L + 5
# if we can make n other drinks out of what's left then the lemonade to beer ratio is...
s = []
for n in count(2):
if n > 100: break
# x/y is the ratio of lemonade to beer
x = B * n - 100
y = 100 - L * n
if not(x > 0 and y > 0): continue
s.append(n) # total number of people
# we're only interested where there is only one way of doing it
if len(s) == 1:
d[s[0]].append("[n={n}] L={L} B={B}".format(n=s[0], L=L, B=B))

# find group sizes that have a unique solution
for (k, v) in d.items():
if len(v) == 1: print(v[0])
```

2. Hugh Casement 7 March 2016 at 10:53 am

I can’t see that we have enough information to solve this.  We don’t know whether each other person received an integer percentage of the total amount of either beer or lemonade, or each had an integer number of fluid drachms (or any other curious unit one cares to name) of each ingredient, nor whether the proportion of lemonade to beer in any or all of the glasses was an integer percentage or even a rational number.  We don’t even know the ratio of the total amounts of lemonade and beer.  Therefore it appears that there could be infinitely many ways of dividing up whatever is left in the jugs after the one drink has been poured.  What am I missing?

• Jim Randell 7 March 2016 at 1:42 pm

If the initial amounts of lemonade and beer (measured in half pints, but not necessarily integers) are L and B, respectively. And there are n people needing drinks altogether.

L + B = n

Then the setter has an integer percentage of both the lemonade and the beer to make a half pint.

So, suppose the setter has k/100 of the lemonade and (k+5)/100 of the beer to make up his half pint.

kL + (k + 5)B = 100
k(L + B) + 5B = 100
B = 20 − kn/5
L = n (k + 5) / 5 − 20

now B > 0, and L > 0:

kn < 100
n(k + 5) > 100

So, for a given value of k > 0 we have:

100 / (k + 5) < n < 100 / k

If we are given k (an integer from 0 to 100), we can determine the possible range for n (a positive integer), without the need to calculate L or B.

And we are told that if we given k, there would be a unique corresponding value of n.

The only single values for n, are when:

k = 15 → n = 6
k = 17, 18, 19 → n = 5
k = 21, 22, 23, 24 → n = 4
k = 29, 30, 31, 32, 33 → n = 3
k = 46, 47, 48, 49 → n = 2

So (k, n) must be one of the pairs above.

We are then told that if we were told n we could determine k.

So the only possible pair is (k, n) = (15, 6).

Plugging these numbers back into the equations we get: B = 2, L = 4, i.e. initially there were 2 half pints (1 pint) of beer and 4 half pints (2 pints) of lemonade.

• Hugh Casement 7 March 2016 at 5:09 pm

Many thanks for your swift response, Jim.  I’ll now read that through (slowly!) and try to understand it.  Numerical integration and even singular-value decomposition are simple in comparison to some of these Enigmata (I’m opting for a Greek plural in line with the expression “it’s all Greek to me”).

This site uses Akismet to reduce spam. Learn how your comment data is processed.