Sunday Times Teaser 2727 – Happy New Year
by Andrew Skidmore
Happy New Year (link)
In five numbers, I have replaced each of the ten digits with a different letter to give:
A VERY HAPPY NEW YEAR
The sum of these numbers is a palindrome and the largest is the sum of the other four.
YEAR is odd. What is its numeric value?
One Comment
Leave one →
-
brian gladman permalink123456789101112131415161718192021from itertools import permutations# permute the letters for HAPPYfor H, A, P, Y in permutations(range(10), 4):HAPPY = 10000 * H + 1000 * A + 110 * P + Y# twice HAPPY is palindromict = str(2 * HAPPY)if 10000 < HAPPY < 100000 and t == t[::-1]:# permute remaining digits for remaining lettersrem = set(range(10)) - set((H, A, P, Y))for E, N, R, V, W in permutations(rem, 5):# compute the other three wordsVERY = 1000 * V + 100 * E + 10 * R + YNEW = 100 * N + 10 * E + WYEAR = 1000 * Y + 100 * E + 10 * A + R# check that YEAR is odd and that the sum is correctif YEAR & 1 and HAPPY == A + VERY + NEW + YEAR:print('A = {}, VERY = {}, HAPPY = {}, NEW = {}, YEAR = {}'.format(A, VERY, HAPPY, NEW, YEAR))