Skip to main content
Bzzzt, hashes for sections
Source Link
Parcly Taxel
  • 3.9k
  • 1
  • 6
  • 45

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.

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) is also explicitly defined as:

$$ Cn = \frac1{n + 1} {2n \choose n} $$

Starting from n = 0, the first 20 Catalan numbers are:

#Challenge

##I/O

###Input

###Output

#Catalog The 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.

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\ge0\$) is also explicitly defined as: $$C_n=\frac1{n+1}\binom{2n}n$$ Starting from \$n=0\$, the first 20 Catalan numbers are:

Challenge

I/O

Input

Output

Catalog

The 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.

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 aa and bb such that any substring starting from the beginning has number of aa characters greater than or equal to number of bb characters, and the entire string has the same number of aa and bb characters) with length 2n2n. The nth Catalan number (for n >= 0n >= 0) is also explicitly defined as:

$$ Cn = \frac1{n + 1} {2n \choose n} $$

Starting from n = 0n = 0, the first 20 Catalan numbers are:

Write a full program or function that takes a non-negative integer nn via STDIN or an acceptable alternative, and outputs the nth Catalan number. Your program must work at minimum for inputs 0-190-19.

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) is also explicitly defined as:

Starting from n = 0, the first 20 Catalan numbers are:

Write a full program or function that takes a non-negative integer n via STDIN or an acceptable alternative, and outputs the nth Catalan number. Your program must work at minimum for inputs 0-19.

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) is also explicitly defined as:

$$ Cn = \frac1{n + 1} {2n \choose n} $$

Starting from n = 0, the first 20 Catalan numbers are:

Write a full program or function that takes a non-negative integer n via STDIN or an acceptable alternative, and outputs the nth Catalan number. Your program must work at minimum for inputs 0-19.

Notice removed Reward existing answer by lyxal
Bounty Ended with math scat's answer chosen by lyxal
Notice added Reward existing answer by lyxal
Bounty Started worth 100 reputation by lyxal

The Catalan numbersCatalan numbers (OEIS) are a sequence of natural numbers often appearing in combinatorics.

The Catalan numbers (OEIS) are a sequence of natural numbers often appearing in combinatorics.

The Catalan numbers (OEIS) are a sequence of natural numbers often appearing in combinatorics.

edited tags
Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975
Loading
[Edit removed during grace period]
Link
a spaghetto
  • 11.3k
  • 3
  • 46
  • 82
Loading
edited tags
Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975
Loading
added 6 characters in body
Source Link
a spaghetto
  • 11.3k
  • 3
  • 46
  • 82
Loading
added 37 characters in body
Source Link
a spaghetto
  • 11.3k
  • 3
  • 46
  • 82
Loading
typo
Source Link
ETHproductions
  • 50.1k
  • 6
  • 94
  • 240
Loading
Tweeted twitter.com/StackCodeGolf/status/674648483278794757
deleted 6 characters in body
Source Link
a spaghetto
  • 11.3k
  • 3
  • 46
  • 82
Loading
Source Link
a spaghetto
  • 11.3k
  • 3
  • 46
  • 82
Loading