2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,12 +1,9 @@
|
|||
defmodule Digital do
|
||||
def root(n, base \\ 10), do: root(n, base, 0)
|
||||
def root(n, base\\10), do: root(n, base, 0)
|
||||
|
||||
def root(n, base, ap) when n < base, do: {n, ap}
|
||||
def root(n, base, ap) do
|
||||
Integer.to_string(n, base)
|
||||
|> String.codepoints
|
||||
|> Enum.reduce(0, fn x,acc -> acc + String.to_integer(x, base) end)
|
||||
|> root(base, ap+1)
|
||||
defp root(n, base, ap) when n < base, do: {n, ap}
|
||||
defp root(n, base, ap) do
|
||||
Integer.digits(n, base) |> Enum.sum |> root(base, ap+1)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue