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


import math
 
for i in 1..<5000:
  var sum: int64 = 0
  var number = i
  while number > 0:
    var digit = number mod 10
    sum += digit ^ digit
    number = number div 10
  if sum == i:
    echo i