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


            NORMAL MODE IS INTEGER
            DIMENSION P(5)
 
            THROUGH CLCPOW, FOR D=0, 1, D.G.5
            P(D) = D
            THROUGH CLCPOW, FOR X=1, 1, X.GE.D
CLCPOW      P(D) = P(D) * D
 
            THROUGH TEST, FOR D1=0, 1, D1.G.5
            THROUGH TEST, FOR D2=0, 1, D2.G.5
            THROUGH TEST, FOR D3=0, 1, D3.G.5
            THROUGH TEST, FOR D4=1, 1, D4.G.5
            N = D1*1000 + D2*100 + D3*10 + D4
            WHENEVER P(D1)+P(D2)+P(D3)+P(D4) .E. N
                PRINT FORMAT FMT,N
TEST        END OF CONDITIONAL
 
            VECTOR VALUES FMT = $I4*$
            END OF PROGRAM 