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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Munchausen numbers step by step in the MAD 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 MAD programming language

Source code in the mad programming language

            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

  

You may also check:How to resolve the algorithm Interactive programming (repl) step by step in the Lingo programming language
You may also check:How to resolve the algorithm Hello world/Newbie step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm Distance and Bearing step by step in the Wren programming language
You may also check:How to resolve the algorithm Even or odd step by step in the SQL programming language
You may also check:How to resolve the algorithm Scope/Function names and labels step by step in the Sidef programming language