exercism/elixir/armstrong-numbers/lib/armstrong_number.ex

14 lines
320 B
Elixir
Raw Normal View History

2024-06-27 02:42:04 +00:00
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