DEV Community

loading...

Discussion on: Daily Challenge #214 - Persistent Bugger

Collapse
savagepixie profile image
SavagePixie

Elixir

defmodule Challenge do
  def persistence(n) do
    n
      |> Integer.digits
      |> _persistence(0)
  end
  defp _persistence([ _ | [] ], x), do: x
  defp _persistence(list, x) do
    list
      |> List.foldl(1, &(&1 * &2))
      |> Integer.digits
      |> _persistence(x + 1)
  end
end