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 แล้วเพิ่มคู่เพื่อนบ้านของแต่ละแถวก่อนหน้า 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. · คลิก Run เพื่อดูผลลัพธ์ที่นี่