Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Motzkin-numbers/Go/motzkin-numbers.go
Normal file
25
Task/Motzkin-numbers/Go/motzkin-numbers.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"rcu"
|
||||
)
|
||||
|
||||
func motzkin(n int) []int {
|
||||
m := make([]int, n+1)
|
||||
m[0] = 1
|
||||
m[1] = 1
|
||||
for i := 2; i <= n; i++ {
|
||||
m[i] = (m[i-1]*(2*i+1) + m[i-2]*(3*i-3)) / (i + 2)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(" n M[n] Prime?")
|
||||
fmt.Println("-----------------------------------")
|
||||
m := motzkin(41)
|
||||
for i, e := range m {
|
||||
fmt.Printf("%2d %23s %t\n", i, rcu.Commatize(e), rcu.IsPrime(e))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue