# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1628: Power crazy

From New Scientist #2794, 8th January 2011 [link]

My godson is 5 years old. When you work out his age raised to a power equal to itself you get 55 = 3125, which ends with his age.

Similarly, if you take my age in years and raise it to a power equal to itself then the answer ends with my age. And if you reverse the two different digits of my age and work out my “reverse age” raised to a power equal to itself then the answer ends with my reverse age.

I was also surprised to find that, if you raise my reverse age to a power equal to my age then the answer also ends with my reverse age.

Clearly I do not expect you to work out any of these powers, as they all consist of over 100 digits! However, you should still be able to answer the question: how old am I?

[enigma1628]

### 3 responses to “Enigma 1628: Power crazy”

1. jimrandell 13 December 2011 at 11:23 pm

Python has bignum support, so it’s not a problem to deal with full powers involved. The program runs in 29ms.

```def check(a, b):
n = a ** b
if len(str(n)) < 101: return False
if not(str(n).endswith(str(a))): return False
return True

for a in range(10, 100):
if a % 11 == 0: continue
if not check(a, a): continue
r = int(str(a)[::-1])
if not check(r, r): continue
if not check(r, a): continue
print(a)
```

Solution: You are 57.

2. Hugh Casement 22 April 2016 at 12:32 pm

My pocket calculator can cope with (the first eight digits of) 56^57 and 57^56 but throws in the sponge at 57^57.  That’s a good indication, I think, that 57 is the lowest integer which when raised to its own power is greater than 1E100.  It turns out to be a very good starting point.

57^4 mod 100 = 1.  56 being a multiple of 4, 57^56 mod 100 also equals 1.
Multiply by an extra 57 and you get a number ending in 57.
All odd powers of 75 end in 75.  So 57 was a lucky guess.

• geoffrounce 23 April 2016 at 7:42 pm

Hi Hugh,
If you install Python 3, you can use the interactive shell as calculator, without writing any code:

>>> 57 ** 57
12158129736671364080886280192352136280305445908985401876990335800107686586023081377754367704855688057
>>> 75 ** 75
426181657761258833198605424151960757395791315610122269092300199179088043392834051588896184557263865748388820264835885609500110149383544921875
>>> 75 ** 57
75594815832868199776770376005214530088120923458388982924968264582969712517268590090679936110973358154296875

Here is another Python 3 solution:

```for age in range(11,100):
if age % 10 == 0: continue
d1, d2 = age // 10, age % 10
if d1 == d2 : continue
s1 = str(age ** age)
if len(s1) < 100 : continue
if s1[-1] == str(d2) and s1[-2] == str(d1):
age2 = 10 * d2 + d1    # reverse initial age
s2 = str(age2 ** age2)
if len(s2) < 100: continue
if s2[-1] == str(d1) and s2[-2] == str(d2):
age3 = age2 ** age
s3 = str(age3)
if len(s3) < 100 : continue
if s3[-1] == str(d1) and s3[-2] == str(d2):
print('My age is :', age)
```

This site uses Akismet to reduce spam. Learn how your comment data is processed.