[ create a new paste ] login | about

Link: http://codepad.org/bLmpfkjD    [ raw code | output | fork ]

mohit_at_codepad - Haskell, pasted on Apr 26:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- Count number of digits in 100!
-- I think the answer is below 192 but above 92
-- One can use sterling's formula to estimate the number of digits

-- Expected output is 158

main = printDigitsInFactorialOf 100 where
       printDigitsInFactorialOf = putStr . show . countDigits . calculateFactorial

calculateFactorial 0 = 1
calculateFactorial n = n * calculateFactorial predn where
                       predn = pred n

countDigits 0 = 0
countDigits n = 1 + countDigits nDiv10 where
                nDiv10 = n `div` 10


Output:
1
158


Create a new paste based on this one


Comments: