Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
This is an anonymous function that accepts an integer and returns an integera float. It uses the basic binomial formula. To call it, give it a name, e.g. f=n->....
Julia, 28 bytes
n->Int(binomial(2n,n)/(n+1))
This is an anonymous function that accepts an integer and returns an integer. It uses the basic binomial formula. To call it, give it a name, e.g. f=n->....
Julia, 23 bytes
n->binomial(2n,n)/(n+1)
This is an anonymous function that accepts an integer and returns a float. It uses the basic binomial formula. To call it, give it a name, e.g. f=n->....
Ungolfed:This is an anonymous function that accepts an integer and returns an integer. It uses the basic binomial formula. To call it, give it a name, e.g. f=n->....
# Read n from STDIN
n = parse(readline())
# Compute the nth Catalan number
c = binomial(2n, n) / (n + 1)
# Print the number as an integer
print(Int(c))
# Read n from STDIN
n = parse(readline())
# Compute the nth Catalan number
c = binomial(2n, n) / (n + 1)
# Print the number as an integer
print(Int(c))
Julia, 28 bytes
n->Int(binomial(2n,n)/(n+1))
This is an anonymous function that accepts an integer and returns an integer. It uses the basic binomial formula. To call it, give it a name, e.g. f=n->....
# Read n from STDIN
n = parse(readline())
# Compute the nth Catalan number
c = binomial(2n, n) / (n + 1)
# Print the number as an integer
print(Int(c))