Bell numbers: Difference between revisions

m
(add PariGP code (from OEIS))
Line 1,527:
 
<lang haskell>bellTri :: [[Integer]]
bellTri =
bellTri = map snd (iterate (f . uncurry (scanl (+))) (1,[1]))
let f xs = (last xs, xs)
where
in map snd (iterate (f xs. =uncurry (lastscanl xs,(+))) (1, xs[1]))
 
bell :: [Integer]
bell = map head bellTri
 
main :: IO ()
main = do
putStrLn "First 10 rows of Bell's Triangle:"
mapM_ print (take 10 bellTri)
putStrLn "First\nFirst 15 Bell numbers:"
mapM_ print (take 15 bell)
putStrLn "50th\n50th Bell number:"
print (bell !! 49)</lang>
</lang>
 
{{out}}
<pre>bellTri :: [[Integer]]
<pre>First 10 rows of Bell's Triangle
bellTri =
[1]
let f xs = (last xs, xs)
[1,2]
bellTri = in map snd (iterate (f . uncurry (scanl (+))) (1, [1]))
[2,3,5]
 
[5,7,10,15]
bell :: [Integer]
[15,20,27,37,52]
bell = map head bellTri
[52,67,87,114,151,203]
 
[203,255,322,409,523,674,877]
main :: IO ()
[877,1080,1335,1657,2066,2589,3263,4140]
main = do
[4140,5017,6097,7432,9089,11155,13744,17007,21147]
<pre> putStrLn "First 10 rows of Bell's Triangle:"
[21147,25287,30304,36401,43833,52922,64077,77821,94828,115975]
mapM_ print (take 10 bellTri)
First putStrLn "\nFirst 15 Bell numbers:"
1
mapM_ print (take 15 bell)
1
putStrLn "\n50th Bell number:"
2
print (bell !! 49)</pre>
5
15
52
203
877
4140
21147
115975
678570
4213597
27644437
190899322
50th Bell number
10726137154573358400342215518590002633917247281
</pre>
 
And, of course, in terms of ''Control.Arrow'' or ''Control.Applicative'', the triangle function could also be written as:
9,655

edits