I need a function which return the product of numbers in the string:
SomeFunc("1234") -> 1 * 2 * 3 * 4 = 24
Here is my code:
lists:foldr(fun(X, Y) -> X * Y end, 1, "1234").
But I get 6497400.
Why and how can I fix the code?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your code is multiplying the ascii codes of the characters, i.e. 49*50*51*52. In order to get your desired result, use
where
$0is the ASCII code for the character ‘0’.