So it is a good idea to send in answers regularly in order to ensure that the Sunday Times sees these teasers as a popular feature.

It is great to hear that you have won one!

]]>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
from enigma import irange, printf # consider initial population # (it's a village, so let's say up to 1000) # males for m in irange(2, 500): # p = initial f / m ratio for p in irange(1, (1000 - m) // m): # females f = p * m # ratio (f + 1) / (m + 1) = p - 1 if not((p - 1) * (m + 1) == f + 1): continue # ratio (f + 3) / (m + 3) is an integer (q, r) = divmod(f + 3, m + 3) if r > 0: continue # final population (after 3 extra couples have moved in) pop = f + m + 6 printf("final population = {pop} [m={m} f={f} p={p} q={q}]") |

I did some analysis to write a more sophisticated program, but by the time I got to “m + 3 is a divisor of 6 greater than 3” there was nothing left for a program to do really.

Unusually I actually sent in an entry for this puzzle. And that might explain the mysterious cheque for £20 I received in the post yesterday.

]]>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
from itertools import count # the initial number of males for m in count(1): # the ratio of females to males for multiple in range(1, 10): # the initial number of females f = multiple * m # the ration decreases by one if a couple move in if f + 1 == (multiple - 1) * (m + 1): # and remains an integer if two more couples move in k, r = divmod(f + 3, m + 3) if not r: print('The final village population is {}'.format(m + f + 6)) raise SystemExit |

The mathematical approach is as follows. With \(n\) and \(k\) integer and \(m\) and \(f\) as the initial number of males and females we have: \[\frac{m}{n}=n\] \[\frac{f+1}{m+1} = n-1\] \[\frac{f+3}{m+3} = k\] Eliminating \(n\) from the first two equations gives: \[f=m(m + 2)\] and substituting this into the third then gives: \[(k-m+1)(m+3)=6\] from which we quickly obtain \(m=k=3\) and \(f=15\), leading to a final village population of 24.

]]>