Solve Project Euler 20
This commit is contained in:
18
src/projectEuler/question20.hs
Normal file
18
src/projectEuler/question20.hs
Normal file
@@ -0,0 +1,18 @@
|
||||
{-
|
||||
n! means n x (n - 1) x ... x 3 x 2 x 1.
|
||||
For example, 10! = 10 x 9 x ... x 3 x 2 x 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!.
|
||||
-}
|
||||
|
||||
import Data.Char (digitToInt)
|
||||
|
||||
read' :: Integer -> String
|
||||
read' = show
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
print $ "Answer: " <> show ans
|
||||
|
||||
ans :: Int
|
||||
ans = sum $ map digitToInt $ read' $ product [1..100]
|
||||
Reference in New Issue
Block a user