Output the n-th Bell Number

JavaScript (ES6), 47 bytes

f=(n,a=[b=1])=>n--?f(n,[b,...a.map(e=>b+=e)]):b
f=(n,a=[b=1])=>--n?f(n,[b,...a.map(e=>b+=e)]):b

First one is 0-indexed, second is 1-indexed.


Haskell, 36 bytes

head.(iterate(last>>=scanl(+))[1]!!)

Uses the triangle method, correctly handles 0, 0-based.


R, 31 bytes

sum(gmp::Stirling2.all(scan()))

uses the Stirling Number of the Second Kind formula and calculates those numbers with the gmp package; reads from stdin and returns the value as a Big Integer; fails for 0; 1-indexed.

Tags:

Math

Code Golf