Sunday Times Yeaser 2546 – Secret Agents
by G Smithers
Published: 10 July 2011 (link)
Secret agents James and George exchange coded messages. The code is given by an addition sum, with different letters replacing different digits. The message is then written below the sum. James needs to send George the time (24-hour clock) at which their next secret operation is to begin. He texts as follows:
THREE + THREE + TWO = EIGHT time: DATA
When does this secret operation begin?
One Comment
Leave one →
-
Brian Gladman permalink1234567891011121314151617181920from itertools import permutationsfrom alphasum import AlphaSumc = AlphaSum(['THREE', 'THREE', 'TWO'], 'EIGHT')for r in c.solve():# find unallocated digitsrem_digits = set(range(10)).difference(r.values())# and permute them for A and Dfor p in permutations(rem_digits):r.update(zip('AD', p))# now calculate the hour and minute values from DATAhour, minute = divmod(int(c.substitute(r, 'DATA')), 100)# and check that they are validif 0 <= hour < 24 and 0 <= minute < 60:print('It starts at {}:{}'.format(hour, minute))