# Find the sum of the digits in factorial of 100 in Erlang

This is a problem in poject Euler:

n! means n × (n − 1) × ... × 3 × 2 × 1

For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.

Find the sum of the digits in the number 100!

I decided to solve it using erlang. This is what I've come up with.

-module(fact).
-compile(export_all).

fact(1) -> 1;
fact(N) -> N*fact(N-1).

tolist(N) when N < 10 -> [N];
tolist(N) when N >= 10 -> tolist(N div 10)++[N rem 10].

sum(List) -> sum(List, 0).
sum([H|T], C) -> sum(T, C + H);
sum([], C) -> C.


factfinds the factorial of the number. toList converts it to a list of integers and sum gets the sum of the integers in the list. I run this program like this:

fact:sum(fact:tolist(fact:fact(100))).


Do I have to use 3 functions? Is there a problem with me doing so?

Should I make another function that calls all 3 functions?

3. For extracting the numerical value from digit symbol - just subtract zero-value($0, number representation in Erlang). So, if accumulate all of this points, get: task_(N)-> lists:foldl(fun(X,Sum)->Sum+X-$0 end,0,integer_to_list(fact(N))).
{"ft_lang_label":"__label__en","ft_lang_prob":0.6772108,"math_prob":0.9984256,"size":883,"snap":"2023-40-2023-50","text_gpt3_token_len":307,"char_repetition_ratio":0.10921501,"word_repetition_ratio":0.08743169,"special_character_ratio":0.41223103,"punctuation_ratio":0.18055555,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9999007,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-10-03T18:55:34Z\",\"WARC-Record-ID\":\"<urn:uuid:0bef6957-6580-4951-bdd6-e5b559c29a47>\",\"Content-Length\":\"157612\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:11fb292b-88e0-44c8-857b-268a760b08d3>\",\"WARC-Concurrent-To\":\"<urn:uuid:f6d9befb-8cf6-4dd0-85b6-270a8318d479>\",\"WARC-IP-Address\":\"104.18.11.86\",\"WARC-Target-URI\":\"https://codereview.stackexchange.com/questions/182151/find-the-sum-of-the-digits-in-factorial-of-100-in-erlang\",\"WARC-Payload-Digest\":\"sha1:75V77UWICA543E73KWTXNVOEN5OUYRBF\",\"WARC-Block-Digest\":\"sha1:7BOLOOEWVGOTR4XEJVW32WTQWMFTJEF7\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233511170.92_warc_CC-MAIN-20231003160453-20231003190453-00687.warc.gz\"}"}