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

Published on 12 May 2024 09:40 PM

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

Source code in the bbc programming language

REM >munchausen
FOR i% = 0 TO 5
  FOR j% = 0 TO 5
    FOR k% = 0 TO 5
      FOR l% = 0 TO 5
        m% = FNexp(i%) + FNexp(j%) + FNexp(k%) + FNexp(l%)
        n% = 1000 * i% + 100 * j% + 10 * k% + l%
        IF m% = n% AND m% > 0 THEN PRINT m%
      NEXT
    NEXT
  NEXT
NEXT
END
:
DEF FNexp(x%)
IF x% = 0 THEN
  = 0
ELSE
  = x% ^ x%


  

You may also check:How to resolve the algorithm Tokenize a string step by step in the Mercury programming language
You may also check:How to resolve the algorithm Infinity step by step in the BQN programming language
You may also check:How to resolve the algorithm Align columns step by step in the Pascal programming language
You may also check:How to resolve the algorithm Abbreviations, easy step by step in the Ruby programming language
You may also check:How to resolve the algorithm Set consolidation step by step in the Kotlin programming language