How to resolve the algorithm Munchausen numbers step by step in the Elixir programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Munchausen numbers step by step in the Elixir 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 Elixir programming language
Source code in the elixir programming language
defmodule Munchausen do
@pow for i <- 0..9, into: %{}, do: {i, :math.pow(i,i) |> round}
def number?(n) do
n == Integer.digits(n) |> Enum.reduce(0, fn d,acc -> @pow[d] + acc end)
end
end
Enum.each(1..5000, fn i ->
if Munchausen.number?(i), do: IO.puts i
end)
You may also check:How to resolve the algorithm Null object step by step in the C++ programming language
You may also check:How to resolve the algorithm Greedy algorithm for Egyptian fractions step by step in the Microsoft Small Basic programming language
You may also check:How to resolve the algorithm Van Eck sequence step by step in the C programming language
You may also check:How to resolve the algorithm Chowla numbers step by step in the Go programming language
You may also check:How to resolve the algorithm World Cup group stage step by step in the J programming language