All problems
Pascal Matrix
Problem
Build the n x n symmetric Pascal matrix:
P[i][j] = C(i + j, i)
where C is the binomial coefficient. Its rows follow the diagonals of Pascal's triangle.
Hint
math.comb(k, r) gives the binomial coefficient directly.
Test cases
case 1
in: [1]
expected: [[1]]
case 2
in: [2]
expected: [[1,1],[1,2]]
case 3
in: [3]
expected: [[1,1,1],[1,2,3],[1,3,6]]
case 4
in: [4]
expected: [[1,1,1,1],[1,2,3,4],[1,3,6,10],[1,4,10,20]]
Starter codePython
def pascal_matrix(n):
# Your code here
pass4 test cases · run your code against them in the editor