Sunday Times Teaser 2515 – No Title
by Des MacHale
Published December 5 2010 (link)
Using each digit just once I wrote down two five-figure numbers. One was a cube and the other was a square. Then I combined these two five-figure numbers to give me a ten-figure number by using one of them to occupy the odd positions (from left to right) and the other to occupy the even positions (again from left to right). Then the four-figure number made up in order from the digits in the prime positions turned out to be prime.
What was the ten-figure number?
One Comment
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425262728from itertools import productfrom number_theory import is_prime# filter a sequence of strings, removing those with duplicate lettersfilter = lambda seq: (x for x in seq if len(set(x)) == len(x))# create a list of five digit squares with no duplicate digitssquares = list(filter(str(x ** 2) for x in range(100, 317)))# create a list of five digit cubes with no duplicate digitscubes = list(filter(str(x ** 3) for x in range(21, 47)))# consider all combinations of squares and cubesfor s, c in product(squares, cubes):# they must have no common digitsif not set(s) & set(c):# interleave them in two ordersfor s, c in ((s, c), (c, s)):# the interleaved stringn = ''.join(x + y for x, y in zip(s, c))# form the potential primep = int(''.join(n[i - 1] for i in (2, 3, 5, 7)))# and check for a primeif(is_prime(p)):# create a list of five digit squares with no duplicate digitsprint(n, (int(s), int(c), p))