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


with javascript_semantics
constant powers = sq_power(tagset(9,0),tagset(9,0))
 
function munchausen(integer n)
    integer n0 = n
    atom total = 0
    while n!=0 do
        total += powers[remainder(n,10)+1]
        n = floor(n/10)
    end while
    return (total==n0)
end function
 
for i=1 to 5000 do
    if munchausen(i) then ?i end if
end for
