Faulhaber's triangle: Difference between revisions
m
→{{header|Haskell}}: Formatting lint, and a salute to Spoon!'s helpful Faulhaber edits
(→{{header|Haskell}}: simpler base case) |
m (→{{header|Haskell}}: Formatting lint, and a salute to Spoon!'s helpful Faulhaber edits) |
||
Line 42:
-- FAULHABER -------------------------------------------------------------------
-- Infinite list of rows of Faulhaber's triangle
faulhaberTriangle :: [[Rational]]
faulhaberTriangle = tail $ scanl fh_ [] [0 ..]
where
fh_ x
where
-- p -> n -> Sum of the p-th powers of the first n positive integers
faulhaber :: Int -> Rational -> Rational
faulhaber p n =
▲faulhaber p n = sum $ zipWith (\nd i -> nd * (n ^ i)) (faulhaberTriangle !! p) [1 ..]
sum $ zipWith (\nd i -> nd * (n ^ i)) (faulhaberTriangle !! p) [1 ..]
-- DISPLAY ---------------------------------------------------------------------
-- (Max numerator+denominator widths) -> Column width -> Filler -> Ratio -> String
justifyRatio :: (Int, Int) -> Int -> Char -> Rational -> String
Line 78:
-- List of Ratios -> (Max numerator width, Max denominator width)
maxWidths :: [[Rational]] -> (Int, Int)
maxWidths xss = (n, d)
where
-- TEST ------------------------------------------------------------------------
|