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

Published on 12 May 2024 09:40 PM

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

Source code in the purebasic programming language

EnableExplicit
Declare main()

If OpenConsole("Munchausen_numbers")
  main() : Input() : End
EndIf

Procedure main()
  Define i.i,
         sum.i,
         number.i,
         digit.i  
  For i = 1 To 5000
    sum = 0
    number = i
    While number > 0
      digit = number % 10
      sum + Pow(digit, digit)
      number / 10
    Wend  
    If sum = i
      PrintN(Str(i))
    EndIf
  Next
EndProcedure

  

You may also check:How to resolve the algorithm SEDOLs step by step in the M4 programming language
You may also check:How to resolve the algorithm Higher-order functions step by step in the C# programming language
You may also check:How to resolve the algorithm Intersecting number wheels step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Special characters step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Variable size/Set step by step in the Fortran programming language