RPK4BJVZAW4J6YENUA2Y54RJGN6N4J6ECUB6OCKJBR3XNWERFXUAC
// Package pascal computes Pascal's triangle
package pascal
// Triangle returns a triangle based on input.
func Triangle(lines int) [][]int {
ret := make([][]int, lines)
for i := 0; i < lines; i++ {
ret[i] = make([]int, i+1)
for j := 0; j < len(ret[i]); j++ {
var left, right int
// handle out of range
if i-1 >= 0 {
if j-1 >= 0 {
left = ret[i-1][j-1]
}
if j < len(ret[i])-1 { // previous line is shorter with 1
right = ret[i-1][j]
}
}
if left+right == 0 {
ret[i][j] = 1
} else {
ret[i][j] = left + right
}
}
}
return ret
}