add solution to problem 20
This commit is contained in:
parent
a4e6849f99
commit
77445e8fbe
1 changed files with 15 additions and 0 deletions
15
problems/20/solution.exs
Normal file
15
problems/20/solution.exs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
defmodule FactDigitSum do
|
||||||
|
defp fact(1, acc), do: acc
|
||||||
|
defp fact(n, acc), do: fact(n - 1, n * acc)
|
||||||
|
def fact(n), do: fact(n - 1, n)
|
||||||
|
|
||||||
|
defp digit_sum(0, acc), do: acc
|
||||||
|
defp digit_sum(n, acc), do: digit_sum(div(n, 10), rem(n, 10) + acc)
|
||||||
|
def digit_sum(n), do: digit_sum(n, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
FactDigitSum.fact(100)
|
||||||
|
|> FactDigitSum.digit_sum()
|
||||||
|
|> IO.puts()
|
||||||
|
|
Loading…
Add table
Reference in a new issue