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?



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

    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
      >>> 75 ** 75
      >>> 75 ** 57

      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)

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: