How to resolve the algorithm Munchausen numbers step by step in the AWK programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Munchausen numbers step by step in the AWK 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 AWK programming language
Source code in the awk programming language
# syntax: GAWK -f MUNCHAUSEN_NUMBERS.AWK
BEGIN {
for (i=1; i<=5000; i++) {
sum = 0
for (j=1; j<=length(i); j++) {
digit = substr(i,j,1)
sum += digit ^ digit
}
if (i == sum) {
printf("%d\n",i)
}
}
exit(0)
}
You may also check:How to resolve the algorithm Pi step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Sum multiples of 3 and 5 step by step in the R programming language
You may also check:How to resolve the algorithm Linear congruential generator step by step in the jq programming language
You may also check:How to resolve the algorithm Synchronous concurrency step by step in the OCaml programming language
You may also check:How to resolve the algorithm Loops/Continue step by step in the Ruby programming language