New Scientist Enigma 519 – Fibonacci Thimbles
by Susan Denham
From Issue #1669, 1st July 1989
One year, on my birthday I started a collection of thimbles. The following birthday l added to my collection, which went from strength to strength. In all subsequent years when I counted the thimbles on my birthday the total had increased from the previous year’s total by a number equal to the total I had on my birthday the year before that. (So, for example, my 1983 total equaled my 1982 total added to my 1981 total.) Now, by coincidence, my daughter was born on my birthday. And, with my collection growing following the described pattern, on our birthday in 1983 the number of thimbles I owned had reached exactly four times my daughter’s age on that day. On my birthday this year the total of thimbles was four times my age. On only one other occasion has the total been divisible by four, and that was in the year my son was born. How many thimbles were there in my collection on my birthday this year? How many (if any) did I have on the day my daughter was born?
-
Brian Gladman permalink1234567891011121314151617181920212223242526272829303132333435363738from itertools import combinations, count# the two starting values for the sequencefor a, b in combinations(range(1, 10), 2):seq, ix = [a, b], []# generate the sequencefor i in count():seq.append(seq[-2] + seq[-1])# look for three values divisible by fourq, r = divmod(seq[i], 4)if not r:ix.append(i)if len(ix) == 3:break# end the sequence if the age becomes too highif q > 100:break# we need three values that are divisible by fourif len(ix) != 3:continue# Susan Denham's age in 1989sd_age = seq[ix[2]] // 4# the Daughter's age occurs in 1983, six years earlierda_age = [seq[i] // 4 for i in ix[:-1] if i == ix[2] - 6]# skip if there is no sequence item divisible by four six# years earlier or if Susan's age as a mother is unlikelyif not da_age or sd_age < 20:continueda_age = da_age[0]# find the son's year of birthsn_year = [i - ix[2] + 1989 for i in ix[:-1] if i != ix[2] - 6][0]# and the number of thimbles, if any, in the daughter's birth yearid = ix[2] - da_age - 6th = seq[id] if id >= 0 else Noneprint(f"{4 * sd_age}, {th} ({sd_age}, {da_age}, {sn_year}) {seq}")