A Munchausen number is a natural number n the sum of whose digits (in base 10), each raised to the power of itself, equals n.

(Munchausen is also spelled: Münchhausen.)

For instance:    3435 = 33 + 44 + 33 + 55 



Task
Find all Munchausen numbers between   1   and   5000.



Also see

 The OEIS entry:  A046253
 The Wikipedia entry:  Perfect digit-to-digit invariant, redirected from Munchausen Number


To run:
Start up.
Show the Munchausen numbers up to 5000.
Wait for the escape key.
Shut down.
 
To show the Munchausen numbers up to a number:
If a counter is past the number, exit.
If the counter is Munchausen, convert the counter to a string; write the string to the console.
Repeat.
 
To decide if a number is Munchausen:
Privatize the number.
Find the sum of the digit self powers of the number.
If the number is the original number, say yes.
Say no.
 
To find the sum of the digit self powers of a number:
If the number is 0, exit.
Put 0 into a sum number.
Loop.
Divide the number by 10 giving a quotient and a remainder.
Put the quotient into the number.
Raise the remainder to the remainder.
Add the remainder to the sum.
If the number is 0, break.
Repeat.
Put the sum into the number.