Sunday Times Teaser 2859 – Palindromic
by Victor Bryant
Published July 9 2017 (link)
I have assigned to each letter of the alphabet a different number from 0 to 25. Therefore, for example, a three-letter word might stand for a number of three, four, five or six digits. In fact all the letters used in PALINDROMIC have even values. Furthermore, the number represented by this word contains no zeros and is indeed palindromic.
Please send in the number represented by PIN.
2 Comments
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425from itertools import permutations# the values for the letters in PALINDROMICdv = {2, 4, 6, 8, 12, 14, 16, 18, 22, 24}# map P to possible C values based on the fact that PALINDROMIC# is a palindromep2c = {2:(12, 22), 4:(14, 24), 6:(16,), 8:(18,), 22:(2,), 24:(2,)}# consider possible values for P and Cfor P in p2c.keys():for C in p2c[P]:# permute the remaining numeric values for the remaining lettersfor p in permutations(dv.difference([P, C])):# create a dictionary mapping letters to their valuesd = dict(zip('ADILMNORPC', p + (P, C)))# find the numeric value of PALINDROMIC as a stringpal = ''.join(str(d[c]) for c in 'PALINDROMIC')# ... and look for a result that is a palindromeif pal == pal[::-1]:pin = ''.join(str(d[c]) for c in 'PIN')t = ', '.join(str(d[c]) for c in 'PALINDROMIC')print(f'PIN = {pin} (PALINDROMIC = {t})')
-
geoffrounce permalink1234567891011from itertools import permutationsnums = (24, 22, 18, 16, 14, 12, 8, 6, 4, 2)for q in permutations(nums):p, a, l, i, n, d, r, o, m, c = (str(x) for x in q)pal = p + a + l + i + n + d + r + o + m + i + cif pal == pal[::-1]:print(f'PIN = {p + i + n}, PALINDROMIC = {pal}')