How to resolve the algorithm Munchausen numbers step by step in the F# programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Munchausen numbers step by step in the F# 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 F# programming language
Source code in the fsharp programming language
let toFloat x = x |> int |> fun n -> n - 48 |> float
let power x = toFloat x ** toFloat x |> int
let isMunchausen n = n = (string n |> Seq.map char |> Seq.map power |> Seq.sum)
printfn "%A" ([1..5000] |> List.filter isMunchausen)
You may also check:How to resolve the algorithm Abstract type step by step in the Skew programming language
You may also check:How to resolve the algorithm Golden ratio/Convergence step by step in the M4 programming language
You may also check:How to resolve the algorithm Sorting algorithms/Pancake sort step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Count in octal step by step in the Modula-2 programming language
You may also check:How to resolve the algorithm Natural sorting step by step in the ATS programming language