Sunday Times Teaser 2894 – Time Duality
by Peter Good
Published March 11 2018 (link)
After a good breakfast, Seb decided on 40 winks. He noted the time on his digital clock as he dozed off. When he woke up a little later that day, not fully alert, he saw the display reflected in a mirror and was amazed by how long he seemed to have slept. This was in fact 10 times the length of his nap. Next day, a similar thing happened: he fell asleep at the same time and slept a little less, but when he woke, the mirror led him to believe he had slept for 20 times as long as he had. (All times were whole numbers of minutes after midnight.)
At what time did he fall asleep?
One Comment
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425262728293031323334353637383940414243444546from collections import defaultdict# dictionary to 'mirror reverse' digital digitsrd = {'0':'0', '1':'1', '2':'5', '5':'2', '8':'8'}# for indexing sleep start times to digital clock wake timest2d = defaultdict(list)# consider the hours and minutes of the possible wake timefor h in range(24):h1 = str(h).zfill(2)for m in range(60):m1 = str(m).zfill(2)t1 = 60 * h + m# reverse the digits and the digit order in this time to obtain the# wake time as seen in the mirror, checking that it is a valid timetry:d2 = ''.join(rd[d] for d in (h1 + m1)[::-1])except KeyError:continueh2, m2 = d2[:2], d2[2:]t2 = 60 * int(h2) + int(m2)if not (0 <= int(h2) < 24 and 0 <= int(m2) < 60):continueif t2 <= t1:t2 += 24 * 60h2 = str(24 + int(h2))# now compute the sleep start time <t> using t2 - t = k.(t1 - t)# for k = 10 and k = 20, giving t = (k.t1 - t2) / (k - 1)for k in (10, 20):t, r = divmod(k * t1 - t2, k - 1)if t and not r:dt = ':'.join(str(x).zfill(2) for x in divmod(t, 60))t2d[dt].append((k, t1 - t, ':'.join((h1, m1)), ':'.join((h2, m2))))# look for a start time that gives solutions for multiples of both 10 and 20for t, vl in t2d.items():if len(vl) > 1:if {vl[0][0], vl[1][0]} == {10, 20}:s = f'{t} ('for v in sorted(vl):s += ', '.join(str(i) for i in v) + '), ('print(s[:-4] + f')')