28Dec/080
Problem 20: Sum of the digits in 100!
This is so similar to problem 16. The problem is:
n! means n (n 1) ... 3 2 1
Find the sum of the digits in the number 100!
Which is cool 'cos I have learned what n! means. My code is:
prob20(N) -> L = lists:seq(N, 1, -1), NBang = lists:foldl(fun(X, Acc) -> Acc * X end, 1, L), sum_the_digits(NBang). sum_the_digits(N) -> L = integer_to_list(N), lists:foldl(fun(X, Acc) -> Acc + list_to_integer([X]) end, 0, L).
I reuse the sum_the_digits function from problem 16. These recent problems have caused me nothing like the trouble of the first 10. Either I am over some initial erlang/fp/maths hump or they admins have the difficulty order wrong.
Oh yeah. I find that I am using lists:foldl all the time.