Sunday Times Teaser 2944 – Happy Families
by Angela Newing
Published February 24 2019 (link)
Oliver lives with his parents, Mike and Nellie, at number 5. In each of numbers 1 to 4 lives a family, like his, with a mother, a father and one child. He tries listing the families in alphabetical order and produces the table below.
House Number | 1_______ | 2_______ | 3_______ | 4_______ | 5_______ |
Fathers | Alan | Dave | George | John | Mike |
Mothers | Beth | Ellen | Helen | Kate | Nellie |
Children | Carole | Freddie | Ingrid | Larry | Oliver |
_______
However, apart from his own family, there is just one father, one mother and one child in the correct position. Neither Helen nor Beth lives at number 3 and neither Dave nor Ingrid lives at number 1. George’s house number is one less than Larry’s and Beth’s house number is one less than Carol’s.
Apart from Oliver’s family, who are correctly positioned?
One Comment
Leave one →
-
Brian Gladman permalink123456789101112131415161718192021222324252627282930313233343536373839404142434445464748from itertools import permutationsfathers = 'Alan Dave George John Mike'.split()mothers = 'Beth Ellen Helen Kate Nellie'.split()children = 'Carole Freddie Ingrid Larry Oliver'.split()# permute only the people in the first four positionsfor mp in permutations(mothers[:4]):# neither Helen nor Beth lives at number 3if any(mp.index(m) == 2 for m in ('Helen', 'Beth')):continue# only one other mother is correctly positionedif sum(mothers.index(m) == n for n, m in enumerate(mp)) != 1:continuefor fp in permutations(fathers[:4]):# only one other father is correctly positionedif sum(fathers.index(f) == n for n, f in enumerate(fp)) != 1:continuefor cp in permutations(children[:4]):# only one other child is correctly positionedif sum(children.index(c) == n for n, c in enumerate(cp)) != 1:continue# neither Dave nor Ingrid lives at number 1if fp.index('Dave') == 0 or cp.index('Ingrid') == 0:continue# George's house number is one less than Larry'sif not fp.index('George') + 1 == cp.index('Larry'):continue# Beth's house number is one less than Carole'sif not mp.index('Beth') + 1 == cp.index('Carole'):continue# find people who are in the correct position in the tablet = ', '.join( [f for n, f in enumerate(fp) if fathers.index(f) == n] +[m for n, m in enumerate(mp) if mothers.index(m) == n] +[c for n, c in enumerate(cp) if children.index(c) == n] )print(' and '.join(t.rpartition(', ')[::2]))