I was helping Ernie clean out his shed a while back when I saw a curious old machine. "Oh yeah, that!" said Ernie, when I pointed it out to him. "A few years back, before transistors were invented, I tried to make a clockwork calculator. It worked, but was never a commercial success." The machine consisted two rows of six sockets, three buttons (labelled A, M, and E) and a short strip of paper emerging from a narrow slot on one side. "Didn't need a key-pad," said Ernie, "instead you would put a plug for each numeral into the sockets, and then press A or M to add or multiply the numbers represented on the two rows. The answer would be printed out on the paper strip. Internally it calculated the units digit of the result first, then the tens, hundreds, etc. It was a bit slow, so I got it to print out each digit as soon as it could, so the digits of the answer were printed out in reverse order."
I had a closer look, the machine had spent a bit too much time sitting under a leaking window, and the bottom row of sockets had rusted out entirely. And the box of plugs only contained one 4, one 6, two 0's, three each of 1, 5 and 7, five each of 8, and 9, and six 2's. There were no 3's left at all. "Yep, looking back I can see it would never have caught on - too easy to lose digits. That's why I never built subtraction or division into it", Ernie commented. "No chance of demonstrating it properly now, but if I swap a couple of cogs over...", Ernie delved into a back panel with a screw-driver for a few seconds, "...I should be able to get something out of it".
Ernie put plugs for 8 and 6 in the 10's 1's slots of the machine, wound the key a couple of turns and hit the button marked A. After a few seconds of humming, a length of paper strip emerged with the digits 2, 7, and 1 on it. "See," he said, "now it reads the digits of both numbers from the top row of sockets. See, 86 + 86 = 172". He added another plug to the hundreds to make 786, gave the key a few more turns and pressed the M button. After a longer pause (and more humming), the digits 6, 9, 7, 7, 1, and 6 emerged in turn on the paper strip. I made a quick calculation on the back of an envelope. "Wow!", I exclaimed, "786*786 = 617,796. It works!".
"Have a go yourself." said Ernie. I removed the plugs from the sockets on the top row, replaced them with some more, and turned the key until it felt tight. "What does the E button do?" I asked. "Oh, Exponentiation." he said, "it used to calculate the first row to the power of the second row, so now it will calculate n^n". I pressed the button. "Can't imagine it completing that calculation before the clockwork runs out" Ernie exclaimed. "And even if it does, I'm sure the paper won't be long enough to print it out". We watched for a couple of minutes, but nothing seemed to happen - the machine hummed gently but no numbers were printed out.
After doing more tidying around the shed for a while (still no print-out), we went back to the house for coffee. When we returned, Ernie was proven right, the clockwork calculator had run down and was humming no longer. But before it stopped, it had printed out a string of digits. To my surprise, the digits, in the order they had been printed were exactly the same as the plugs (reading left to right) that I had inserted into the upper sockets.
I can't remember exactly what the number I used was, but do remember that at the time I worked out that the digits were all correct and I had chosen the largest possible number that could be entered into the calculator with that result. Can you help me remember what the number was?
In other words, we're looking for an $n$, consisting of no more than $6$ of the following digits: $\{0,0,1,1,1,2,2,2,2,2,2,4,5,5,5,6,7,7,7,8,8,8,8,8,9,9,9,9,9\}$, such that $n^n$ ends with the digits of $n$ in reverse order.