2011/05/02

[Puzzle]人過大佛寺*4=寺佛大過人,猜數字

Palindrome:
abcde*4 = edcba
[a,b,c,d,e] are five distinct decimal digits.

Use python to do brutal force searching:
#!/usr/bin/env python

revStr = lambda s:s[len(s)-1:0:-1]+s[0]
revInt = lambda n:int(revStr(str(n)))
isPalin = lambda a,b:revInt(a)==(b)
is4div = lambda n:n%4==0
biglist = range(1,99999)
quadMul = filter(is4div, biglist)
isQuoPalin = lambda n:isPalin(n/4,n)
blist = filter(isQuoPalin, quadMul)

"""
>>> print blist
[8712, 87912]
"""

The final answer is 87912/4 = 21978. So, 21978*4 = 87912.

No comments: