The nth Catalan number is the number of Dyck words (balanced strings of parenthesis or brackets such as [[][]]
; formally defined as a string using two characters a
and b
such that any substring starting from the beginning has number of a
characters greater than or equal to number of b
characters, and the entire string has the same number of a
and b
characters) with length 2n
. The nth Catalan number (for n >= 0
\$n\ge0\$) is also explicitly defined as:
$$ Cn = \frac1{n + 1} {2n \choose n} $$
Starting
$$C_n=\frac1{n+1}\binom{2n}n$$
Starting from n = 0
\$n=0\$, the first 20 Catalan numbers are:
#Challenge
Challenge
##I/O
I/O
###Input
Input
###Output
Output
Catalog
#Catalog TheThe Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.