Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Digital-root/Elixir/digital-root.elixir
Normal file
22
Task/Digital-root/Elixir/digital-root.elixir
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
defmodule Digital do
|
||||
def root(n, base\\10), do: root(n, base, 0)
|
||||
|
||||
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
|
||||
|
||||
data = [627615, 39390, 588225, 393900588225]
|
||||
Enum.each(data, fn n ->
|
||||
{dr, ap} = Digital.root(n)
|
||||
IO.puts "#{n} has additive persistence #{ap} and digital root of #{dr}"
|
||||
end)
|
||||
|
||||
base = 16
|
||||
IO.puts "\nBase = #{base}"
|
||||
fmt = "~.#{base}B(#{base}) has additive persistence ~w and digital root of ~w~n"
|
||||
Enum.each(data, fn n ->
|
||||
{dr, ap} = Digital.root(n, base)
|
||||
:io.format fmt, [n, ap, dr]
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue