Skip to content

Instantly share code, notes, and snippets.

@ryanwinchester
Last active January 14, 2017 01:39
Show Gist options
  • Select an option

  • Save ryanwinchester/b3e39235354483c284326dd0c4595dc8 to your computer and use it in GitHub Desktop.

Select an option

Save ryanwinchester/b3e39235354483c284326dd0c4595dc8 to your computer and use it in GitHub Desktop.
defmodule PersistentBugger do
@moduledoc """
Calculate multiplicative persistence.
https://www.codewars.com/kata/persistent-bugger/train/elixir
"""
def persistence(num, count \\ 0) when num < 10, do: count
def persistence(num, count \\ 0) do
num
|> Integer.digits
|> multiply
|> do_persistence(count + 1)
end
defp multiply([i | n]), do: Enum.reduce(n, i, &(&1 * &2))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment