Bell numbers: Difference between revisions

julia example
(→‎{{header|Factor}}: add two more methods)
(julia example)
Line 277:
[21147 25287 30304 36401 43833 52922 64077 77821 94828 115975]
</pre>
 
 
=={{header|Julia}}==
Source: Combinatorics at https://github.com/JuliaMath/Combinatorics.jl/blob/master/src/numbers.jl
<lang julia>"""
bellnum(n)
Compute the ``n``th Bell number.
"""
function bellnum(n::Integer)
if n < 0
throw(DomainError(n))
elseif n < 2
return 1
end
list = Vector{BigInt}(undef, n)
list[1] = 1
for i = 2:n
for j = 1:i - 2
list[i - j - 1] += list[i - j]
end
list[i] = list[1] + list[i - 1]
end
return list[n]
end
 
for i in 1:50
println(bellnum(i))
end
</lang>{{out}
<pre>
1
2
5
15
52
203
877
4140
21147
115975
678570
4213597
27644437
190899322
1382958545
10480142147
82864869804
682076806159
5832742205057
51724158235372
474869816156751
4506715738447323
44152005855084346
445958869294805289
4638590332229999353
49631246523618756274
545717047936059989389
6160539404599934652455
71339801938860275191172
846749014511809332450147
10293358946226376485095653
128064670049908713818925644
1629595892846007606764728147
21195039388640360462388656799
281600203019560266563340426570
3819714729894818339975525681317
52868366208550447901945575624941
746289892095625330523099540639146
10738823330774692832768857986425209
157450588391204931289324344702531067
2351152507740617628200694077243788988
35742549198872617291353508656626642567
552950118797165484321714693280737767385
8701963427387055089023600531855797148876
139258505266263669602347053993654079693415
2265418219334494002928484444705392276158355
37450059502461511196505342096431510120174682
628919796303118415420210454071849537746015761
10726137154573358400342215518590002633917247281
185724268771078270438257767181908917499221852770
</pre>
 
 
=={{header|Perl 6}}==
4,108

edits