Problem 20
The problem number 20 of the Euler project aims to find the sum of the digits in the number 100!. First, I defined the factorial function, as follows:
import Char
fac n = foldr (*) 1 [1..n]
Then, I just defined a function that calculates the factorial of a given number and performs some transformations in order to sum the digits of that number. The function was defined as one can see below:
sumF = sum . map digitToInt . show . fac
Then, by executing sumF 100
, one gets the correctresult for this problem.
blog comments powered by Disqus