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


 
x : 10 1
 
 (2^2) x.2
 (3^3) x.3
 (4^4) x.4
 (5^5) x.5
 (6^6) x.6
 (7^7) x.7
 (8^8) x.8
 (9^9) x.9
 
 1 i
 if i <= 5000
    ~ i $i          | convert binary to string
    #$i j           | length to j
    y               | set y to 0 
    if j > 0
       $i.j $j 1    | move digit j to string j
       ~ $j n       | convert j string to binary
       + x.n y      | add value x at n to y
       - j          | dec j 
       goif
    endif
    if i = y
       i []         | output to console
    endif
    + i
    goif
 endif
 
 