Skip to content

Problem 20

November 21, 2009

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 correct result for this problem.

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: