package main
import "fmt"
func main() {
YangHuiTriangle(10)
}
func YangHuiTriangle(n int) []int {
i := n - 1
line := make([]int, n)
if i <= 0 {
line = []int{1}
fmt.Println(line)
return line
}
down := YangHuiTriangle(i)
for x := 0; x < n; x++ {
if x == 0 {
line[0] = 1
continue
}
if x == n-1 {
line[x] = 1
continue
}
line[x] = down[x-1] + down[x]
}
fmt.Println(line)
return line
}
結果:
如有更好方法請指教