Jump to content

Stirling numbers of the second kind: Difference between revisions

m
Line 458:
import qualified Data.MemoCombinators as Memo
 
stirling2 :: Integral a => (a ->, a) -> a
stirling2 = Memo.memo2pair Memo.integral Memo.integral f
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), k) + stirling2 (pred n), (pred k)
 
main :: IO ()
Line 474:
printf "%s\n" $ replicate (13 * 10 + 3) '-'
mapM_ (\row -> printf "%2d|" (fst $ head row) >>
mapM_ (printf "%10d" . uncurry stirling2) row >> printf "\n") table
printf "\nThe maximum value of S2(100, k):\n%d\n" $
maximum ([stirling2 (100, n) | n <- [1..100]] :: [Integer])
where
table :: [[(Int, Int)]]
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.