4 Star 25 Fork 17

编程语言算法集 / Go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
catalannumber.go 842 Bytes
一键复制 编辑 原始数据 按行查看 历史
// catalannumber.go
// description: Returns the Catalan number
// details:
// In combinatorial mathematics, the Catalan numbers are a sequence of natural numbers that occur in various counting problems, often involving recursively defined objects. - [Catalan number](https://en.wikipedia.org/wiki/Catalan_number)
// The input is the number of the Catalan number n, at the output we get the value of the number
// author(s) [red_byte](https://github.com/i-redbyte)
// see catalannumber_test.go
package catalan
import (
f "github.com/TheAlgorithms/Go/math/factorial"
)
func factorial(n int) int {
result, error := f.Iterative(n)
if error != nil {
panic(error)
}
return result
}
// CatalanNumber This function returns the `nth` Catalan number
func CatalanNumber(n int) int {
return factorial(n*2) / (factorial(n) * factorial(n+1))
}
Go
1
https://gitee.com/TheAlgorithms/Go.git
git@gitee.com:TheAlgorithms/Go.git
TheAlgorithms
Go
Go
master

搜索帮助