Cody

# Problem 1463. Pascal's Matrix

Solution 237083

Submitted on 28 Apr 2013 by Marco Castelli
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
%% user_solution = fileread('pascalMat.m'); assert(isempty(strfind(user_solution,'regexp'))); assert(isempty(strfind(user_solution,'2str'))); assert(isempty(strfind(user_solution,'str2'))); assert(isempty(strfind(user_solution,'interp'))); assert(isempty(strfind(user_solution,'printf'))); assert(isempty(strfind(user_solution,'assert')));

2   Pass
%% n = 0; P_correct = [ 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = 1

3   Pass
%% n = 1; P_correct = [ 1 0 1 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = 1 0 1 1

4   Pass
%% n = 2; P_correct = [ 1 0 0 1 1 0 1 2 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = 1 0 0 1 1 0 1 2 1

5   Pass
%% n = 3; P_correct = [ 1 0 0 0 1 1 0 0 1 2 1 0 1 3 3 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = 1 0 0 0 1 1 0 0 1 2 1 0 1 3 3 1

6   Pass
%% n = 4; P_correct = [ 1 0 0 0 0 1 1 0 0 0 1 2 1 0 0 1 3 3 1 0 1 4 6 4 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = 1 0 0 0 0 1 1 0 0 0 1 2 1 0 0 1 3 3 1 0 1 4 6 4 1

7   Pass
%% n = 5; P_correct = [ 1 0 0 0 0 0 1 1 0 0 0 0 1 2 1 0 0 0 1 3 3 1 0 0 1 4 6 4 1 0 1 5 10 10 5 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = 1 0 0 0 0 0 1 1 0 0 0 0 1 2 1 0 0 0 1 3 3 1 0 0 1 4 6 4 1 0 1 5 10 10 5 1

8   Pass
%% n = 6; P_correct = [ 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 2 1 0 0 0 0 1 3 3 1 0 0 0 1 4 6 4 1 0 0 1 5 10 10 5 1 0 1 6 15 20 15 6 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 2 1 0 0 0 0 1 3 3 1 0 0 0 1 4 6 4 1 0 0 1 5 10 10 5 1 0 1 6 15 20 15 6 1

9   Pass
%% n = 7; P_correct = [ 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 2 1 0 0 0 0 0 1 3 3 1 0 0 0 0 1 4 6 4 1 0 0 0 1 5 10 10 5 1 0 0 1 6 15 20 15 6 1 0 1 7 21 35 35 21 7 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 2 1 0 0 0 0 0 1 3 3 1 0 0 0 0 1 4 6 4 1 0 0 0 1 5 10 10 5 1 0 0 1 6 15 20 15 6 1 0 1 7 21 35 35 21 7 1

10   Pass
%% n = 8; P_correct = [ 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 1 3 3 1 0 0 0 0 0 1 4 6 4 1 0 0 0 0 1 5 10 10 5 1 0 0 0 1 6 15 20 15 6 1 0 0 1 7 21 35 35 21 7 1 0 1 8 28 56 70 56 28 8 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 1 3 3 1 0 0 0 0 0 1 4 6 4 1 0 0 0 0 1 5 10 10 5 1 0 0 0 1 6 15 20 15 6 1 0 0 1 7 21 35 35 21 7 1 0 1 8 28 56 70 56 28 8 1

11   Pass
%% n = 9; P_correct = [ 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 1 3 3 1 0 0 0 0 0 0 1 4 6 4 1 0 0 0 0 0 1 5 10 10 5 1 0 0 0 0 1 6 15 20 15 6 1 0 0 0 1 7 21 35 35 21 7 1 0 0 1 8 28 56 70 56 28 8 1 0 1 9 36 84 126 126 84 36 9 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 1 3 3 1 0 0 0 0 0 0 1 4 6 4 1 0 0 0 0 0 1 5 10 10 5 1 0 0 0 0 1 6 15 20 15 6 1 0 0 0 1 7 21 35 35 21 7 1 0 0 1 8 28 56 70 56 28 8 1 0 1 9 36 84 126 126 84 36 9 1

12   Pass
%% n = 10; P_correct = [ 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 1 3 3 1 0 0 0 0 0 0 0 1 4 6 4 1 0 0 0 0 0 0 1 5 10 10 5 1 0 0 0 0 0 1 6 15 20 15 6 1 0 0 0 0 1 7 21 35 35 21 7 1 0 0 0 1 8 28 56 70 56 28 8 1 0 0 1 9 36 84 126 126 84 36 9 1 0 1 10 45 120 210 252 210 120 45 10 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 1 3 3 1 0 0 0 0 0 0 0 1 4 6 4 1 0 0 0 0 0 0 1 5 10 10 5 1 0 0 0 0 0 1 6 15 20 15 6 1 0 0 0 0 1 7 21 35 35 21 7 1 0 0 0 1 8 28 56 70 56 28 8 1 0 0 1 9 36 84 126 126 84 36 9 1 0 1 10 45 120 210 252 210 120 45 10 1

13   Pass
%% n = 11; P_correct = [ 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 1 3 3 1 0 0 0 0 0 0 0 0 1 4 6 4 1 0 0 0 0 0 0 0 1 5 10 10 5 1 0 0 0 0 0 0 1 6 15 20 15 6 1 0 0 0 0 0 1 7 21 35 35 21 7 1 0 0 0 0 1 8 28 56 70 56 28 8 1 0 0 0 1 9 36 84 126 126 84 36 9 1 0 0 1 10 45 120 210 252 210 120 45 10 1 0 1 11 55 165 330 462 462 330 165 55 11 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 1 3 3 1 0 0 0 0 0 0 0 0 1 4 6 4 1 0 0 0 0 0 0 0 1 5 10 10 5 1 0 0 0 0 0 0 1 6 15 20 15 6 1 0 0 0 0 0 1 7 21 35 35 21 7 1 0 0 0 0 1 8 28 56 70 56 28 8 1 0 0 0 1 9 36 84 126 126 84 36 9 1 0 0 1 10 45 120 210 252 210 120 45 10 1 0 1 11 55 165 330 462 462 330 165 55 11 1

14   Pass
%% n = 12; P_correct = [ 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 1 3 3 1 0 0 0 0 0 0 0 0 0 1 4 6 4 1 0 0 0 0 0 0 0 0 1 5 10 10 5 1 0 0 0 0 0 0 0 1 6 15 20 15 6 1 0 0 0 0 0 0 1 7 21 35 35 21 7 1 0 0 0 0 0 1 8 28 56 70 56 28 8 1 0 0 0 0 1 9 36 84 126 126 84 36 9 1 0 0 0 1 10 45 120 210 252 210 120 45 10 1 0 0 1 11 55 165 330 462 462 330 165 55 11 1 0 1 12 66 220 495 792 924 792 495 220 66 12 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 1 3 3 1 0 0 0 0 0 0 0 0 0 1 4 6 4 1 0 0 0 0 0 0 0 0 1 5 10 10 5 1 0 0 0 0 0 0 0 1 6 15 20 15 6 1 0 0 0 0 0 0 1 7 21 35 35 21 7 1 0 0 0 0 0 1 8 28 56 70 56 28 8 1 0 0 0 0 1 9 36 84 126 126 84 36 9 1 0 0 0 1 10 45 120 210 252 210 120 45 10 1 0 0 1 11 55 165 330 462 462 330 165 55 11 1 0 1 12 66 220 495 792 924 792 495 220 66 12 1

15   Pass
%% n = 13; P_correct = [ 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 0 1 3 3 1 0 0 0 0 0 0 0 0 0 0 1 4 6 4 1 0 0 0 0 0 0 0 0 0 1 5 10 10 5 1 0 0 0 0 0 0 0 0 1 6 15 20 15 6 1 0 0 0 0 0 0 0 1 7 21 35 35 21 7 1 0 0 0 0 0 0 1 8 28 56 70 56 28 8 1 0 0 0 0 0 1 9 36 84 126 126 84 36 9 1 0 0 0 0 1 10 45 120 210 252 210 120 45 10 1 0 0 0 1 11 55 165 330 462 462 330 165 55 11 1 0 0 1 12 66 220 495 792 924 792 495 220 66 12 1 0 1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = Columns 1 through 8 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 2 1 0 0 0 0 0 1 3 3 1 0 0 0 0 1 4 6 4 1 0 0 0 1 5 10 10 5 1 0 0 1 6 15 20 15 6 1 0 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 9 36 84 126 126 84 36 1 10 45 120 210 252 210 120 1 11 55 165 330 462 462 330 1 12 66 220 495 792 924 792 1 13 78 286 715 1287 1716 1716 Columns 9 through 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 9 1 0 0 0 0 45 10 1 0 0 0 165 55 11 1 0 0 495 220 66 12 1 0 1287 715 286 78 13 1

16   Pass
%% n = 14; P_correct = [ 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 0 0 1 3 3 1 0 0 0 0 0 0 0 0 0 0 0 1 4 6 4 1 0 0 0 0 0 0 0 0 0 0 1 5 10 10 5 1 0 0 0 0 0 0 0 0 0 1 6 15 20 15 6 1 0 0 0 0 0 0 0 0 1 7 21 35 35 21 7 1 0 0 0 0 0 0 0 1 8 28 56 70 56 28 8 1 0 0 0 0 0 0 1 9 36 84 126 126 84 36 9 1 0 0 0 0 0 1 10 45 120 210 252 210 120 45 10 1 0 0 0 0 1 11 55 165 330 462 462 330 165 55 11 1 0 0 0 1 12 66 220 495 792 924 792 495 220 66 12 1 0 0 1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1 0 1 14 91 364 1001 2002 3003 3432 3003 2002 1001 364 91 14 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = Columns 1 through 8 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 2 1 0 0 0 0 0 1 3 3 1 0 0 0 0 1 4 6 4 1 0 0 0 1 5 10 10 5 1 0 0 1 6 15 20 15 6 1 0 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 9 36 84 126 126 84 36 1 10 45 120 210 252 210 120 1 11 55 165 330 462 462 330 1 12 66 220 495 792 924 792 1 13 78 286 715 1287 1716 1716 1 14 91 364 1001 2002 3003 3432 Columns 9 through 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 9 1 0 0 0 0 0 45 10 1 0 0 0 0 165 55 11 1 0 0 0 495 220 66 12 1 0 0 1287 715 286 78 13 1 0 3003 2002 1001 364 91 14 1

17   Pass
%% n = 15; P_correct = [ 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 3 3 1 0 0 0 0 0 0 0 0 0 0 0 0 1 4 6 4 1 0 0 0 0 0 0 0 0 0 0 0 1 5 10 10 5 1 0 0 0 0 0 0 0 0 0 0 1 6 15 20 15 6 1 0 0 0 0 0 0 0 0 0 1 7 21 35 35 21 7 1 0 0 0 0 0 0 0 0 1 8 28 56 70 56 28 8 1 0 0 0 0 0 0 0 1 9 36 84 126 126 84 36 9 1 0 0 0 0 0 0 1 10 45 120 210 252 210 120 45 10 1 0 0 0 0 0 1 11 55 165 330 462 462 330 165 55 11 1 0 0 0 0 1 12 66 220 495 792 924 792 495 220 66 12 1 0 0 0 1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1 0 0 1 14 91 364 1001 2002 3003 3432 3003 2002 1001 364 91 14 1 0 1 15 105 455 1365 3003 5005 6435 6435 5005 3003 1365 455 105 15 1 ]; assert(isequal(pascalMat(n),P_correct));

ans = Columns 1 through 8 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 2 1 0 0 0 0 0 1 3 3 1 0 0 0 0 1 4 6 4 1 0 0 0 1 5 10 10 5 1 0 0 1 6 15 20 15 6 1 0 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 9 36 84 126 126 84 36 1 10 45 120 210 252 210 120 1 11 55 165 330 462 462 330 1 12 66 220 495 792 924 792 1 13 78 286 715 1287 1716 1716 1 14 91 364 1001 2002 3003 3432 1 15 105 455 1365 3003 5005 6435 Columns 9 through 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 9 1 0 0 0 0 0 0 45 10 1 0 0 0 0 0 165 55 11 1 0 0 0 0 495 220 66 12 1 0 0 0 1287 715 286 78 13 1 0 0 3003 2002 1001 364 91 14 1 0 6435 5005 3003 1365 455 105 15 1