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


*        Munchausen numbers        16/03/2019
MUNCHAU  CSECT
         USING  MUNCHAU,R12        base register
         LR     R12,R15            set addressability
         L      R3,=F'5000'        for do i=1 to 5000
         LA     R6,1               i=1
LOOPI    SR     R10,R10              s=0
         LR     R0,R6                ii=i
         LA     R11,4                for do j=1 to 4
         LA     R7,P10               j=1
LOOPJ    L      R8,0(R7)               d=p10(j)
         LR     R4,R0                  ii
         SRDA   R4,32                  ~
         DR     R4,R8                  (n,r)=ii/d
         SLA    R5,2                   ~
         L      R1,POW(R5)             pow(n+1)
         AR     R10,R1                 s=s+pow(n+1)
         LR     R0,R4                  ii=r
         LA     R7,4(R7)               j++
         BCT    R11,LOOPJ            enddo j
         CR     R10,R6               if s=i
         BNE    SKIP                 then
         XDECO  R6,PG                  edit i
         XPRNT  PG,L'PG                print i
SKIP     LA     R6,1(R6)             i++
         BCT    R3,LOOPI           enddo i
         BR     R14                return to caller
POW      DC     F'0',F'1',F'4',F'27',F'256',F'3125',4F'0'
P10      DC     F'1000',F'100',F'10',F'1'
PG       DC     CL12' '            buffer
         REGEQU
         END    MUNCHAU 