2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -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