Sunday Times Teaser 2898 – My Valentine
by Graham Smithers
Published April 8 2018 (link)
Using only positive digits, MILLY wrote down a two-digit number and a nine-digit number, both numbers being divisible by 14.
Splitting her nine-digit number into three three-digit numbers, she noticed that all three numbers were also divisible by 14.
Systematically replacing different digits by different letters, her two-digit number and nine-digit number ended up as MY VALENTINE.
What number is represented by MILLY?
2 Comments
Leave one →
-
Brian Gladman permalink123456789101112131415161718192021222324from itertools import permutationsfn = lambda s, n: [x for x in s if '0' not in x and len(set(x)) == n]# two digit multiples of 14 without zero or repeated digitsd2 = fn(list(str(14 * x) for x in range(1, 8)), 2)# three digit multiples of 14 without zero or repeated digitsd3 = fn(list(str(14 * x) for x in range(8, 72)), 3)# consider possible values for 'my'for my in d2:# ... and possible values for 'val' and 'ent'for val, ent in permutations(d3, 2):# 'my', 'val' and 'ent' must have 8 different digits, leaving just oned, *r = set('123456789').difference(my + val + ent)if not r:ine = d + ent[1] + ent[0]if ine in d3:# note: checking that 'valentine' is divisible by 14 is unnecessarymilly = my[0] + ine[0] + val[2] * 2 + my[1]print(f'MILLY = {milly} (MY = {my}, VALENTINE = {val}{ent}{ine}).')
-
geoffrounce permalink12345678910from itertools import permutationsfor my in (14, 28, 42, 56, 84, 98):m, y = divmod(my, 10)# check three three-digit numbers for divisibility by 14for v, a, l, e, n, t, i in permutations(set('123456789').difference(str(my))):if not any(int(x) % 14 for x in (v + a + l, e + n + t, i + n + e)):print(f'MILLY = {10000 * m + 1000 * int(i) + 110 * int(l) + y}')