Ticket #4276: test.hs

File test.hs, 0.5 KB (added by guest, 3 years ago)
Line 
1{-# LANGUAGE BangPatterns #-}
2module Main where
3
4import Data.List
5import System.Environment
6
7sum' xs = foldl' (+) 0 xs
8
9sumf_meshes f a b w0 = (s0, w0) : go s0 w0 where
10        s0 = sum' . map f . takeWhile (<= b) $ [a + k*w0 | k <- map fromIntegral [0..]]
11        go s w = (s', w') : go s' w' where
12                s' = (+s) . sum' . map f . takeWhile (<= b) $ [a + w' + k*w | k <- map fromIntegral [0..]]
13                w' = w/2
14
15main = do
16        str:_ <- getArgs
17        let n = read str
18            f u = (exp . negate $ u ) / u
19        mapM_ print . take n $ sumf_meshes f 1 23 22
20        return ()