Last active
January 14, 2017 01:39
-
-
Save ryanwinchester/b3e39235354483c284326dd0c4595dc8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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