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

Published on 12 May 2024 09:40 PM

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

Source code in the raku programming language

sub is_munchausen ( Int $n ) {
    constant @powers = 0, |map { $_ ** $_ }, 1..9;
    $n == @powers[$n.comb].sum;
}
.say if .&is_munchausen for 1..5000;


  

You may also check:How to resolve the algorithm 99 bottles of beer step by step in the HolyC programming language
You may also check:How to resolve the algorithm Comments step by step in the Hope programming language
You may also check:How to resolve the algorithm Comments step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Compare sorting algorithms' performance step by step in the Julia programming language
You may also check:How to resolve the algorithm Play recorded sounds step by step in the R programming language