Anonymous user
Stirling numbers of the second kind: Difference between revisions
m
→{{header|Haskell}}
Line 458:
import qualified Data.MemoCombinators as Memo
stirling2 :: Integral a => (a
stirling2 = Memo.
where
f (n, k)
| n == 0 && k == 0 = 1
| (n > 0 && k == 0) || (n == 0 && k > 0) = 0
| n == k = 1
| k > n = 0
| otherwise = k * stirling2 (pred n
main :: IO ()
Line 474:
printf "%s\n" $ replicate (13 * 10 + 3) '-'
mapM_ (\row -> printf "%2d|" (fst $ head row) >>
mapM_ (printf "%10d" .
printf "\nThe maximum value of S2(100, k):\n%d\n" $
maximum ([stirling2 (100, n) | n <- [1..100]] :: [Integer])
where
table :: [[(Int, Int)]]
|