Sunday Times Teaser 2543 – Hit and Miss
by Victor Bryant
Published: 19 June 2011 (link)
For calculations using arithmetic in a base higher than 10 I need symbols for the higher “digits”. My digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A(=10), B(=11), C(=12), etc, using as many letters as necessary. But some numbers are ambiguous. Eg in HIT and in MISS it is unclear whether the second digit is the number 1 or the letter I. So there are four interpretations of HIT + MISS. I’ve taken one of those four interpretations and worked out its remainder when dividing by four. If you knew the remainder you could work out which base I am using.
What is that base?
One Comment
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425262728293031from itertools import productfrom collections import defaultdict# the values of the letters usedH, I, M, S, T = 17, 18, 22, 28, 29# a dictionary that maps from the two I values# to a map from the (HIT + MISS) mod 4 value# to the bases that give this valued = defaultdict(lambda:defaultdict(list))# the possible base valuesfor b in range(30, 37):# try all four combinations of I valuesfor i1, i2 in product((1, 18), repeat=2):# form HIT and MISShit = (H * b + i1) * b + Tmiss = ((M * b + i2) * b + S) * b + S# ... and compile the two mapsd[(i1, i2)][(hit + miss) % 4].append(b)# scan the maps for a pair of keys that give a# unique base valuefor rem_to_bases in d.values():for l_bases in rem_to_bases.values():if len(l_bases) == 1:print('The base is {}'.format(*l_bases))