Brain-Teaser 522: [Palindromic phone numbers]
From The Sunday Times, 13th June 1971 [link]
The other day I noticed some strange coincidences about the telephone numbers of my three friends.
Each number reads the same from left to right and vice versa. The first and third digit formed the owner’s age, as did the sum of all the digits of his number and, furthermore, his number was divisible by his age.
What were my friends’ ages?
This puzzle was originally published with no title.
[teaser522]
Jim Randell 11:20 am on 11 June 2020 Permalink |
Assuming the ages cannot have a leading zero (which means the phone numbers can’t either) gives us a unique solution to the puzzle.
This Python program uses the [[
SubstitutedExpression()]] solver from the enigma.py library to try 3-, 4- and 5-digit numbers satisfying the required conditions. It runs in 54ms.from enigma import (sprintf as f, join, SubstitutedExpression, subsets, all_different, printf) # alphametic forms for possible palindromic phone numbers numbers = [ 'ABA', 'ABBA', 'ABCBA' ] # collect possible (number, age) solutions ss = list() # consider possible phone numbers for n in numbers: # age is 1st and 3rd digit a = n[0] + n[2] exprs = [ # sum of digits is the same as age f("{s} = {a}", s=join(n, sep=" + ")), # the number itself is divisible by the age f("{n} % {a} = 0"), ] # solve the alphametic expressions p = SubstitutedExpression(exprs, distinct="", answer=f("({n}, {a})")) ss.extend(p.answers(verbose=0)) # choose three solutions with different ages for (A, B, C) in subsets(ss, size=3): if not all_different(A[1], B[1], C[1]): continue printf("A={A} B={B} C={C}")Solution: The ages are: 21, 23, 27.
The corresponding phone numbers are: 28182, 28382, 28782.
These are the only three solutions for 5-digit phone numbers, and there are no solutions for 3- or 4-digit phone numbers.
LikeLike
GeoffR 4:48 pm on 16 July 2021 Permalink |
LikeLike