How to resolve the algorithm Munchausen numbers step by step in the 360 Assembly programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Munchausen numbers step by step in the 360 Assembly programming language

Table of Contents

Problem Statement

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

Find all Munchausen numbers between   1   and   5000.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Munchausen numbers step by step in the 360 Assembly programming language

Source code in the 360 programming language

*        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

  

You may also check:How to resolve the algorithm Strip a set of characters from a string step by step in the Python programming language
You may also check:How to resolve the algorithm Program termination step by step in the VBA programming language
You may also check:How to resolve the algorithm Old lady swallowed a fly step by step in the Lua programming language
You may also check:How to resolve the algorithm Sort three variables step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Greatest subsequential sum step by step in the Ring programming language