Sunday Times Teaser 2781 – Number Time
by Susan Bricket
Published: 10 January 2016 (link)
I have written down some numbers and then consistently replaced digits by capital letters, with different letters used for different digits. In this way my numbers have become
TRIPLE (which is a multiple of three)
EIGHT (which is a cube)
NINE (which is divisible by nine)
PRIME (which is a prime)
What is the number TIME?
One Comment
Leave one →

Brian Gladman permalink1234567891011121314151617181920212223242526272829303132333435from itertools import permutationsfrom number_theory import is_primeheader = 'EIGHT NINE PRIME TRIPLE > TIME'fs = '{:3d}^3 {:4d} {:5d} {:6d} {:4d}'# start with possible cube valuesfor c in range(22, 47):# extract its digitsE, I, G, H, T = (int(x) for x in str(c ** 3))# now find N such that NINE is a multiple of nine using the fact that# the sum of digits of a number divisible by 9 is also divisible by 9N = (4 * (I + E)) % 9# check that N and T are not zero and that we have 6 different digitss4 = set(range(10)).difference([E, I, G, H, T, N])if 0 not in (N, T) and len(s4) == 4:# now permute the remaining digitsfor L, M, P, R in permutations(s4):# and form PRIME and TRIPLEprime = 10000 * P + 1000 * R + 100 * I + 10 * M + Etriple = 100000 * T + 10000 * R + 1000 * I + 100 * P + 10 * L + E# P is not zero, PRIME is prime and TRIPLE is a multiple of 3if P and is_prime(prime) and triple % 3 == 0:time = 1000 * T + 100 * I + 10 * M + Eif header:print(header)header = Noneprint(fs.format(c, 1010 * N + 100 * I + E, prime, triple, time))