Create a Pascal's Triangle that is a nested list and contains zeros in the unused spots.
In the output array, the numbers of Pascal's Triangle are separated by zeroes and padded by zeroes on each side so that they are centered. For example, the bottom row (last sub-array) must have no zeroes on the left and the right; the second-last sub-array has one zero padding on each side, and so on.
Here is the output for input 5
:
[[0,0,0,0,1,0,0,0,0],
[0,0,0,1,0,1,0,0,0],
[0,0,1,0,2,0,1,0,0],
[0,1,0,3,0,3,0,1,0],
[1,0,4,0,6,0,4,0,1]]
As usual, the solution with the fewest bytes wins.
print("def pascal(n):\n #make the nested list\n a=[[0 for i in range(2*n+1)] for j in range(n+1)] #make the list\n a[0][n]=1 #add the initial 1\n for i in range(1,n+1):\n for j in range(2*n+1):\n a[i][j]=a[i-1][j-1]+a[i-1][(j+1)%(2*n+1)] #the main part\n return a")
\$\endgroup\$