Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/Catalan-numbers/Go/catalan-numbers-1.go
Normal file
13
Task/Catalan-numbers/Go/catalan-numbers-1.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var b, c big.Int
|
||||
for n := int64(0); n < 15; n++ {
|
||||
fmt.Println(c.Div(b.Binomial(n*2, n), c.SetInt64(n+1)))
|
||||
}
|
||||
}
|
||||
27
Task/Catalan-numbers/Go/catalan-numbers-2.go
Normal file
27
Task/Catalan-numbers/Go/catalan-numbers-2.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
func c(n int64) *big.Int {
|
||||
if n == 0 {
|
||||
return big.NewInt(1)
|
||||
} else {
|
||||
var t1, t2, t3, t4, t5, t6 big.Int
|
||||
t1.Mul(big.NewInt(2), big.NewInt(n))
|
||||
t2.Sub(&t1, big.NewInt(1))
|
||||
t3.Mul(big.NewInt(2), &t2)
|
||||
t4.Add(big.NewInt(n), big.NewInt(1))
|
||||
t5.Mul(&t3, c(n-1))
|
||||
t6.Div(&t5, &t4)
|
||||
return &t6
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
for n := int64(1); n < 16; n++ {
|
||||
fmt.Println(c(n))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue