Teaser 2701: Flipping ages!
From The Sunday Times, 29th June 2014 [link] [link]
At a recent family party the ages of the ten people present formed an arithmetic progression (i.e. the difference between each person’s age in years and the age of the next oldest person was always the same). My age was like my wife’s but with the digits in reverse order. Likewise, my sister’s age was the reverse of my mother’s, my son’s age was the reverse of my grandson’s, and my daughter’s age was the reverse of my granddaughter’s. Furthermore, the product of my brother’s age and the age of his son equalled the year of birth of one of the people at the party.
What were the ages of my brother, my sister and myself (in that order)?
[teaser2701]
Jim Randell 9:30 am on 21 March 2023 Permalink |
This Python program chooses the 4 pairs of ages that are the mutually reversed, and then extends this set of 8 numbers to 10 numbers in arithmetic progression (if possible). It then allocates the given relationships between the numbers (it looks for viable parent/child ages where the parent is between 16 and 50 years older than the child).
Runtime is 282ms.
Run: [ @replit ]
from enigma import (irange, subsets, union, tuples, mgcd, call, divisor, div, decompose, diff, printf) # collect pairs that are the reverse of each other pairs = set((10 * a + b, 10 * b + a) for (a, b) in subsets(irange(1, 9), size=2)) # generate arithmetic progressions based on the given numbers def generate(ns): ns = sorted(ns) (a, z) = (ns[0], ns[-1]) # find potential common differences for d in divisor(call(mgcd, (y - x for (x, y) in tuples(ns, 2)))): # calculate number of terms k = div(z - a, d) if k is None or k > 9: continue k += 1 # pad the sequence to bring it to 10 terms for (pa, pz) in decompose(10 - k, 2, increasing=0, sep=0, min_v=0): # construct the new sequence ns = list(irange(a - pa * d, z + pz * d, step=d)) yield ns # check for viable parent, child age check = lambda parent, child: 15 < parent - child < 51 # choose 4 pairs for ps in subsets(pairs, size=4): ss = union(ps) for ns in generate(ss): # the additional ages are brother and nephew (nep, bro) = diff(ns, ss) if not check(bro, nep): continue # and their product is the birth year of one of the party year = bro * nep x = 2014 - year if not { x, x - 1 }.intersection(ns): continue # choose the pairs for ((sis, mum), (gson, son), (gdtr, dtr), other) in subsets(ps, size=4, select="P"): # check parent/child relationships if not (check(mum, sis) and check(mum, bro)): continue if not (check(son, gson) or check(dtr, gson)): continue if not (check(son, gdtr) or check(dtr, gdtr)): continue # the remaining pair is (me, wife) (in some order) for (me, wife) in subsets(other, size=2, select="P"): # check parent/child relationships if not (check(mum, me) and check(me, son) and check(me, dtr)): continue if not (check(wife, son) and check(wife, dtr)): continue # output solution printf("{ns}") printf("-> me={me} wife={wife}") printf("-> sis={sis} mum={mum}") printf("-> son={son} gson={gson}") printf("-> dtr={dtr} gdtr={gdtr}") printf("-> bro={bro} nep={nep}; year={year}") printf()Solution: Brother = 60. Sister = 69. Self = 78.
The arithmetic progression is (15, 24, 33, 42, 51, 60, 69, 78, 87, 96).
And the pairs are:
And the product of the ages of the brother and nephew give 1980. And if the 33 year-old nephew has not yet celebrated his birthday in 2014, his year of birth is 1980.
But we can’t tell how the child/grandchild pairs correspond to the son/grandson and daughter/granddaughter pairs.
LikeLike