Sunday Times Teaser 2670 – Answers on a Postcard
by Andrew Skidmore
I have four two digit whole numbers, none of which is a multiple of three.
These numbers use eight consecutive digits in total and the digits in three of them are consecutive in some order.
I have calculated their sum and product and, after consistently using different letters to represent different digits, I find that these translate to SUM and PRODUCT respectively.
What number does POSTCARD represent?
One Comment
Leave one →
-
brian gladman permalink1234567891011121314151617181920212223242526272829from itertools import combinations, permutations# two digit numbers not divisible by threenbrs_all = { x for x in range(10, 100) if x % 3 }# and those with consecutive digitsnbrs_con = { x for x in nbrs_all if abs(x // 10 - x % 10) == 1 }# one number does not have consecutive digitsfor a in nbrs_all - nbrs_con:# three numbers have consecutive digitsfor b, c, d in combinations(nbrs_con, 3):# check for eight different, consecutive digitsdigits = sorted(''.join(str(x) for x in (a, b, c, d)))if len(set(digits)) == 8 and int(digits[0]) + 7 == int(digits[7]):# the sum and the product of the four numbers as stringssn, pn = str(a + b + c + d), str(a * b * c * d)# check that SUM and PRODUCT are the right length with nine# different digits in all and U representing the same digitif ( len(sn) == 3 and len(pn) == 7 andlen(set(sn + pn)) == 9 and sn[1] == pn[4] ):# find the unused digit (which must represent A)md, = set('0123456789') - set(sn + pn)# now map the ten letters to the ten diigitsd = dict(zip('PRODUCTSMA', pn + sn[0] + sn[2] + md))# and form the number represented by POSTCARDp = ''.join(d[x] for x in 'POSTCARD')print('POSTCARD represents {}.'.format(p))