Sunday Times Teaser 2911 – Remembering PINs
by Graham Smithers
Published July 8 2018 (link)
My 10-year-old grandson has several PINs of various lengths to remember. To help him in this, he has systematically replaced different digits by different letters to get corresponding words as THREE, FIVE, SIX, SEVEN, NINE, TEN and FIFTEEN. Being very clever, he has arranged it so that each PIN is divisible by the number specified by the corresponding word.
What is his PIN for FIFTEEN?
2 Comments
Leave one →
-
Brian Gladman permalink123456789101112131415161718192021222324252627from itertools import permutationswds = ((3, 'THREE'), (5, 'FIVE'), (6, 'SIX'), (7, 'SEVEN'),(9, 'NINE'), (10, 'TEN'), (15, 'FIFTEEN'))# convert a word to a number using the letter to digit dictionary l2dw2n = lambda s: ''.join(l2d[c] for c in s)# permute digits for the letters EFINTfor p in permutations('0123456789', 5):l2d = dict(zip('EFINT', p))# check that the last three words, when converted to numbers,# are divisible by the number described by the wordif all(int(w2n(w)) % n == 0 for n, w in wds[4:]):# permute the remaining digits for HRSVXfor q in permutations(set('0123456789').difference(p)):l2d.update(zip('HRSVX', q))# check that the first four words, when converted to numbers,# are divisible by the number described by the wordif all(int(w2n(w)) % n == 0 for n, w in wds[:4]):print('\n'.join(f'PIN[{w}] = {w2n(w)}' for n, w in wds))print()
-
geoffrounce permalink123456789101112131415161718192021222324252627282930313233343536373839404142from itertools import permutationsfor p1 in permutations ('1234567890', 4):# find digits T, H, R, Et, h, r, e = p1three = int(t + h + r + e + e)if three % 3 != 0: continueq1 = set('1234567890') - set(p1)# find digits F, V, Nfor p2 in permutations(q1, 3):f, v, n = p2ten = int(t + e + n)if ten % 10 != 0: continue# find digits S, I, Xq2 = set(q1) - set(p2)for p3 in permutations(q2):s, i, x = p3five = int(f + i + v + e)if five % 5 != 0: continuesix = int(s + i + x)if six % 6 != 0: continueseven = int(s + e + v + e + n)if seven % 7 != 0: continuenine = int(n + i + n + e)if nine % 9 != 0: continuefifteen = int(f + i + f + t + e + e + n)if fifteen % 15 != 0: continueprint ('FIFTEEN = ', fifteen)print('THREE={}, FIVE={}, SIX={}, SEVEN={}, NINE={}, TEN={}' \.format(three, five,six, seven, nine, ten))