Stirling numbers of the first kind: Difference between revisions

m
(added Haskell)
Line 490:
main :: IO ()
main = do
printf "n/k"
mapM_ (printf "%10d") ([0..12] :: [Int]) >> printf "\n"
mapM_ (\row -> printf "%3ds\n" $ replicate (fst13 $* head10 row+ 3) >> '-'
mapM_ (\row -> printf "%2d|" (fst $ head row) >>
mapM_ (printf "%10d" . uncurry sterling1) row >> printf "\n") table
printprintf $"\nThe maximum [sterling1value of S1(100, k):\n | %d\n" <- [1..100]]$
maximum ([sterling1 100 n | n <- [1..100]] :: [Integer])
where
table :: [[(Int, Int)]]
table = groupedByXgroupBy (\a b -> fst a == fst b) $ (,) <$> [0..12] <*> [0..12]</lang>
groupedByX = groupBy (\a b -> fst a == fst b)</lang>
 
Or library: monad-memo for memoization. Seems to be a few milliseconds slower.
Line 523:
main :: IO ()
main = do
printf "n/k"
mapM_ (printf "%10d") ([0..12] :: [Int]) >> printf "\n"
mapM_ (\row -> printf "%3ds\n" $ replicate (fst13 $* head10 row+ 3) >> '-'
mapM_ (\row -> printf "%2d|" (fst $ head row) >>
mapM_ (printf "%10d" . uncurry sterling1Memo) row >> printf "\n") table
printprintf $"\nThe maximum [sterling1Memovalue of S1(100, k):\n | %d\n" <- [1..100]]$
maximum ([sterling1Memo 100 n | n <- [1..100]] :: [Integer])
where
table :: [[(Int, Int)]]
table = groupedByXgroupBy (\a b -> fst a == fst b) $ (,) <$> [0..12] <*> [0..12]</lang>
groupedByX = groupBy (\a b -> fst a == fst b)</lang>
{{out}}
<pre>n/k 0 1 2 3 4 5 6 7 8 9 10 11 12
-------------------------------------------------------------------------------------------------------------------------------------
0 1 0 0 0 0 0 0 0 0 0 0 0 0
0| 1 1 0 10 0 0 0 0 0 0 0 0 0 0 0
2 1| 0 1 10 0 0 0 0 0 0 0 0 0 0
3 2| 0 21 31 10 0 0 0 0 0 0 0 0 0
4 3| 0 62 11 3 6 1 1 0 0 0 0 0 0 0 0 0
4| 5 0 0 6 24 11 50 356 10 1 1 0 0 0 0 0 0 0 0
5| 6 0 0 24 120 27450 225 35 85 10 15 1 1 0 0 0 0 0 0 0
6| 7 0 0 120 720 274 1764 1624225 735 85 175 15 21 1 1 0 0 0 0 0 0
7| 8 0 0 720 5040 130681764 13132 1624 6769 735 1960 175 322 21 28 1 1 0 0 0 0 0
8| 9 0 0 5040 40320 10958413068 118124 13132 67284 6769 22449 1960 4536 322 546 28 36 1 1 0 0 0 0
109| 0 362880 40320 1026576 109584 1172700 118124 723680 26932567284 6327322449 94504536 870546 4536 1 0 0 0
1110| 0 3628800 362880 10628640 127535761026576 84095001172700 3416930 723680 902055 269325 157773 63273 18150 9450 1320 870 55 45 1 0 0
1211| 0 39916800 1205438403628800 150917976 10525807610628640 4599573012753576 13339535 8409500 2637558 3416930 357423 902055 32670157773 18150 1925 1320 66 55 1 0
12| 0 39916800 120543840 150917976 105258076 45995730 13339535 2637558 357423 32670 1925 66 1
 
The maximum value of S1(100, k):
19710908747055261109287881673376044669240511161402863823515728791076863288440277983854056472903481625299174865860036734731122707870406148096000000000000000000</pre>
 
Anonymous user