Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
17
Task/Bernoulli-numbers/Haskell/bernoulli-numbers.hs
Normal file
17
Task/Bernoulli-numbers/Haskell/bernoulli-numbers.hs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
module Main where
|
||||
|
||||
import Data.Ratio
|
||||
import System.Environment
|
||||
|
||||
main = getArgs >>= printM . defaultArg where
|
||||
defaultArg as = if null as then 60 else read (head as)
|
||||
|
||||
printM m = mapM_ (putStrLn . printP) . takeWhile ((<= m).fst)
|
||||
. filter (\(_,b) -> b /= 0%1) . zip [0..] $ bernoullis
|
||||
|
||||
printP (i,r) = "B(" ++ show i ++ ")=" ++ show (numerator r) ++ "/" ++ show (denominator r)
|
||||
|
||||
bernoullis = map head . iterate (ulli 1) . map berno $ enumFrom 0 where
|
||||
berno i = 1 % (i+1)
|
||||
ulli _ [_] = []
|
||||
ulli i (x:y:xs) = (i%1)*(x-y) : ulli (i+1) (y:xs)
|
||||
Loading…
Add table
Add a link
Reference in a new issue