14 lines
320 B
Elixir
14 lines
320 B
Elixir
|
defmodule ArmstrongNumber do
|
||
|
@moduledoc """
|
||
|
Provides a way to validate whether or not a number is an Armstrong number
|
||
|
"""
|
||
|
|
||
|
@spec valid?(integer) :: boolean
|
||
|
def valid?(number) do
|
||
|
digits = Integer.digits(number)
|
||
|
power = length(digits)
|
||
|
|
||
|
Enum.reduce(digits, 0, &(&1 ** power + &2)) == number
|
||
|
end
|
||
|
end
|