- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
minChunksSize=1000.0 -- 100.0
facbig :: Integer -> Integer
facbig n =
let
divisionProportion = 0.9 -- 2.0/3.0
amountOfChunk = truncate $ logBase divisionProportion $ minChunksSize/fromIntegral n
proportions = map (divisionProportion^) [amountOfChunk, amountOfChunk-1 .. 1]
centralChunkResults = map product [
let
begin = proportionToItemNumber 1 beginRangeProportion
end = proportionToItemNumber 0 endRangeProportion
in
[begin..end] | (endRangeProportion, beginRangeProportion) <- zip proportions $ tail proportions ]
beginChunkResult = product [1 .. proportionToItemNumber 0 $ last proportions]
endChunkResult = product [proportionToItemNumber 1 $ head proportions .. n]
in product $ beginChunkResult:endChunkResult:centralChunkResults
where
proportionToItemNumber shift proportion =
shift + truncate ((1.0-proportion)*fromIntegral n)
fac n = if n <= (truncate $ 3.0*minChunksSize)
then product [1..n]
else facbig n
main = print $ length $ show $ fac 100000
HaskellGovno 10.05.2012 00:34 # +1
bormand 10.05.2012 05:34 # +2
TheHamstertamer 29.05.2012 10:42 # 0
guest 29.05.2012 12:31 # +2
А вообще читаем алгоритм вычисления факториала тут:
http://gmplib.org/manual/Factorial-Algorithm.html#Factorial-Algorithm
JavaGovno 29.05.2012 15:16 # +1
bormand 29.05.2012 16:09 # 0
3.14159265 29.05.2012 16:16 # +1
http://www.willamette.edu/~fruehr/haskell/evolution.html