Anonymous user
Stirling numbers of the first kind: Difference between revisions
m
→{{header|Haskell}}
Line 479:
import qualified Data.MemoCombinators as Memo
where
f n k
Line 486:
| n > 0 && k == 0 = 0
| k > n = 0
| otherwise =
main :: IO ()
Line 494:
printf "%s\n" $ replicate (13 * 10 + 3) '-'
mapM_ (\row -> printf "%2d|" (fst $ head row) >>
mapM_ (printf "%10d" . uncurry
printf "\nThe maximum value of S1(100, k):\n%d\n" $
maximum ([
where
table :: [[(Int, Int)]]
Line 508:
import Control.Monad.Memo (MonadMemo, memo, startEvalMemo, for2)
| n == 0 && k == 0 = pure 1
| n > 0 && k == 0 = pure 0
| k > n = pure 0
| otherwise = do
f1 <- for2 memo
f2 <- for2 memo
pure (f1 + pred n * f2)
main :: IO ()
Line 527:
printf "%s\n" $ replicate (13 * 10 + 3) '-'
mapM_ (\row -> printf "%2d|" (fst $ head row) >>
mapM_ (printf "%10d" . uncurry
printf "\nThe maximum value of S1(100, k):\n%d\n" $
maximum ([
where
table :: [[(Int, Int)]]
|