python方法
def triangles():
N = [1]
while True:
yield N
N.append(0) #尾部加一个零
print(N)
N = [N[i - 1] + N[i] for i in range(len(N))]
n = 0
for t in triangles():
print(t)
n = n + 1
if n == 10:
break
js方法
let a = [1];
for (let i = 0; i <= 10; i++) {
console.log(a);
a[i + 1] = 0;
b = [...a];
for (let j = 0; j <= i + 1; j++) {
if (j == 0) {
a[j] = 1;
} else {
a[j] = b[j - 1] + b[j];
}
}
}