A row of Pascal's triangle · 杨辉三角的一行
A row of Pascal's triangle
Every number in Pascal's triangle is the sum of the two numbers just above it, and every row starts and ends with 1.
Build the rows one at a time. A new row starts with 1, then adds each neighbouring pair of the previous row, row[i] + row[i + 1], and ends with 1. After n rounds, row is the answer. In China the same triangle is named after Yang Hui, who described it in 1261.
杨辉三角的一行
杨辉三角中每个数都等于它正上方两个数之和,每一行都以 1 开头、以 1 结尾。
一行一行地建立。新的一行先放 1,再依次加入上一行每对相邻数之和 row[i] + row[i + 1],最后放 1。重复 n 次后,row 就是答案。南宋数学家杨辉在 1261 年的著作中记载了这个三角形,西方则称它为帕斯卡三角形。
Write pascal_row(n) that returns row n of Pascal's triangle, counting the top row [1] as row 0. Row 4 is [1, 4, 6, 4, 1]. · 编写 pascal_row(n),返回杨辉三角(帕斯卡三角形)的第 n 行,最上面的 [1] 算作第 0 行。第 4 行是 [1, 4, 6, 4, 1]。
Click Run to see the output here. · 点击“运行”查看此处输出。