From 454937e2b85a4290e4a58d541f235cfabb8d1d40 Mon Sep 17 00:00:00 2001 From: Bill Ewanick Date: Wed, 15 Nov 2023 17:05:40 -0500 Subject: [PATCH] Solve Project Euler 20 --- src/projectEuler/question20.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/projectEuler/question20.hs diff --git a/src/projectEuler/question20.hs b/src/projectEuler/question20.hs new file mode 100644 index 0000000..3c47852 --- /dev/null +++ b/src/projectEuler/question20.hs @@ -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]