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


isMunchausen := proc(n::posint) 
local num_digits; 
num_digits := map(x -> StringTools:-Ord(x) - 48, StringTools:-Explode(convert(n, string))); 
return evalb(n = convert(map(x -> x^x, num_digits), `+`)); 
end proc;
 
Munchausen_upto := proc(n::posint) local k, count, list_num; 
list_num := []; 
for k to n do 
    if isMunchausen(k) then 
       list_num := [op(list_num), k]; 
    end if; 
end do; 
return list_num; 
end proc;
 
Munchausen_upto(5000);