dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.8 KiB
1.8 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 69b1028d6e265413d0198a29 | Challenge 230: Pascal's Triangle Row | 29 | challenge-230 |
--description--
Given an integer n, return the nth row of Pascal's triangle as an array.
In Pascal's Triangle, each row begins and ends with 1, and each interior value is the sum of the two values directly above it.
Here are the first 5 rows of the triangle:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
--hints--
pascal_row(5) should return [1, 4, 6, 4, 1].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(pascal_row(5), [1, 4, 6, 4, 1])`)
}})
pascal_row(3) should return [1, 2, 1].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(pascal_row(3), [1, 2, 1])`)
}})
pascal_row(1) should return [1].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(pascal_row(1), [1])`)
}})
pascal_row(10) should return [1, 9, 36, 84, 126, 126, 84, 36, 9, 1].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(pascal_row(10), [1, 9, 36, 84, 126, 126, 84, 36, 9, 1])`)
}})
pascal_row(15) should return [1, 14, 91, 364, 1001, 2002, 3003, 3432, 3003, 2002, 1001, 364, 91, 14, 1].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(pascal_row(15), [1, 14, 91, 364, 1001, 2002, 3003, 3432, 3003, 2002, 1001, 364, 91, 14, 1])`)
}})
--seed--
--seed-contents--
def pascal_row(n):
return n
--solutions--
def pascal_row(n):
if n == 1:
return [1]
row = [1]
for _ in range(2, n + 1):
next_row = [1]
for i in range(1, len(row)):
next_row.append(row[i - 1] + row[i])
next_row.append(1)
row = next_row
return row