Cody

# Problem 1463. Pascal's Matrix

Solution 1920169

Submitted on 3 Sep 2019
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));

P = 1

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

P = 1 1 1 2

Assertion failed.

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

P = 1 1 1 1 2 3 1 3 6

Assertion failed.

5   Fail
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));

P = 1 1 1 1 1 2 3 4 1 3 6 10 1 4 10 20

Assertion failed.

6   Fail
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));

P = 1 1 1 1 1 1 2 3 4 5 1 3 6 10 15 1 4 10 20 35 1 5 15 35 70

Assertion failed.

7   Fail
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));

P = 1 1 1 1 1 1 1 2 3 4 5 6 1 3 6 10 15 21 1 4 10 20 35 56 1 5 15 35 70 126 1 6 21 56 126 252

Assertion failed.

8   Fail
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));

P = 1 1 1 1 1 1 1 1 2 3 4 5 6 7 1 3 6 10 15 21 28 1 4 10 20 35 56 84 1 5 15 35 70 126 210 1 6 21 56 126 252 462 1 7 28 84 210 462 924

Assertion failed.

9   Fail
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));

P = 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 1 3 6 10 15 21 28 36 1 4 10 20 35 56 84 120 1 5 15 35 70 126 210 330 1 6 21 56 126 252 462 792 1 7 28 84 210 462 924 1716 1 8 36 120 330 792 1716 3432

Assertion failed.

10   Fail
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));

P = 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 1 3 6 10 15 21 28 36 45 1 4 10 20 35 56 84 120 165 1 5 15 35 70 126 210 330 495 1 6 21 56 126 252 462 792 1287 1 7 28 84 210 462 924 1716 3003 1 8 36 120 330 792 1716 3432 6435 1 9 45 165 495 1287 3003 6435 12870

Assertion failed.

11   Fail
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));

P = 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 1 3 6 10 15 21 28 36 45 55 1 4 10 20 35 56 84 120 165 220 1 5 15 35 70 126 210 330 495 715 1 6 21 56 126 252 462 792 1287 2002 1 7 28 84 210 462 924 1716 3003 5005 1 8 36 120 330 792 1716 3432 6435 11440 1 9 45 165 495 1287 3003 6435 12870 24310 1 10 55 220 715 2002 5005 11440 24310 48620

Assertion failed.

12   Fail
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));

P = 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 1 3 6 10 15 21 28 36 45 55 66 1 4 10 20 35 56 84 120 165 220 286 1 5 15 35 70 126 210 330 495 715 1001 1 6 21 56 126 252 462 792 1287 2002 3003 1 7 28 84 210 462 924 1716 3003 5005 8008 1 8 36 120 330 792 1716 3432 6435 11440 19448 1 9 45 165 495 1287 3003 6435 12870 24310 43758 1 10 55 220 715 2002 5005 11440 24310 48620 92378 1 11 66 286 1001 3003 8008 19448 43758 92378 184756

Assertion failed.

13   Fail
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));

P = 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 1 3 6 10 15 21 28 36 45 55 66 78 1 4 10 20 35 56 84 120 165 220 286 364 1 5 15 35 70 126 210 330 495 715 1001 1365 1 6 21 56 126 252 462 792 1287 2002 3003 4368 1 7 28 84 210 462 924 1716 3003 5005 8008 12376 1 8 36 120 330 792 1716 3432 6435 11440 19448 31824 1 9 45 165 495 1287 3003 6435 12870 24310 43758 75582 1 10 55 220 715 2002 5005 11440 24310 48620 92378 167960 1 11 66 286 1001 3003 8008 19448 43758 92378 184756 352716 1 12 78 364 1365 4368 12376 31824 75582 167960 352716 705432

Assertion failed.

14   Fail
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));

P = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 1 3 6 10 15 21 28 36 45 55 66 78 91 1 4 10 20 35 56 84 120 165 220 286 364 455 1 5 15 35 70 126 210 330 495 715 1001 1365 1820 1 6 21 56 126 252 462 792 1287 2002 3003 4368 6188 1 7 28 84 210 462 924 1716 3003 5005 8008 12376 18564 1 8 36 120 330 792 1716 3432 6435 11440 19448 31824 50388 1 9 45 165 495 1287 3003 6435 12870 24310 43758 75582 125970 1 10 55 220 715 2002 5005 11440 24310 48620 92378 167960 293930 1 11 66 286 1001 3003 8008 19448 43758 92378 184756 352716 646646 1 12 78 364 1365 4368 12376 31824 75582 167960 352716 705432 1352078 1 13 91 455 1820 6188 18564 50388 125970 293930 646646 1352078 2704156

Assertion failed.

15   Fail
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));

P = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 3 6 10 15 21 28 36 45 55 66 78 91 105 1 4 10 20 35 56 84 120 165 220 286 364 455 560 1 5 15 35 70 126 210 330 495 715 1001 1365 1820 2380 1 6 21 56 126 252 462 792 1287 2002 3003 4368 6188 8568 1 7 28 84 210 462 924 1716 3003 5005 8008 12376 18564 27132 1 8 36 120 330 792 1716 3432 6435 11440 19448 31824 50388 77520 1 9 45 165 495 1287 3003 6435 12870 24310 43758 75582 125970 203490 1 10 55 220 715 2002 5005 11440 24310 48620 92378 167960 293930 497420 1 11 66 286 1001 3003 8008 19448 43758 92378 184756 352716 646646 1144066 1 12 78 364 1365 4368 12376 31824 75582 167960 352716 705432 1352078 2496144 1 13 91 455 1820 6188 18564 50388 125970 293930 646646 1352078 2704156 5200300 1 14 105 560 2380 8568 27132 77520 203490 497420 1144066 2496144 5200300 10400600

Assertion failed.

16   Fail
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));

P = Columns 1 through 14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 3 6 10 15 21 28 36 45 55 66 78 91 105 1 4 10 20 35 56 84 120 165 220 286 364 455 560 1 5 15 35 70 126 210 330 495 715 1001 1365 1820 2380 1 6 21 56 126 252 462 792 1287 2002 3003 4368 6188 8568 1 7 28 84 210 462 924 1716 3003 5005 8008 12376 18564 27132 1 8 36 120 330 792 1716 3432 6435 11440 19448 31824 50388 77520 1 9 45 165 495 1287 3003 6435 12870 24310 43758 75582 125970 203490 1 10 55 220 715 2002 5005 11440 24310 48620 92378 167960 293930 497420 1 11 66 286 1001 3003 8008 19448 43758 92378 184756 352716 646646 1144066 1 12 78 364 1365 4368 12376 31824 75582 167960 352716 705432 1352078 2496144 1 13 91 455 1820 6188 18564 50388 125970 293930 646646 1352078 2704156 5200300 1 14 105 560 2380 8568 27132 77520 203490 497420 1144066 2496144 5200300 10400600 1 15 120 680 3060 11628 38760 116280 319770 817190 1961256 4457400 9657700 20058300 Column 15 1 15 120 680 3060 11628 38760 116280 319770 817190 1961256 4457400 9657700 20058300 40116600

Assertion failed.

17   Fail
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));

P = Columns 1 through 14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 3 6 10 15 21 28 36 45 55 66 78 91 105 1 4 10 20 35 56 84 120 165 220 286 364 455 560 1 5 15 35 70 126 210 330 495 715 1001 1365 1820 2380 1 6 21 56 126 252 462 792 1287 2002 3003 4368 6188 8568 1 7 28 84 210 462 924 1716 3003 5005 8008 12376 18564 27132 1 8 36 120 330 792 1716 3432 6435 11440 19448 31824 50388 77520 1 9 45 165 495 1287 3003 6435 12870 24310 43758 75582 125970 203490 1 10 55 220 715 2002 5005 11440 24310 48620 92378 167960 293930 497420 1 11 66 286 1001 3003 8008 19448 43758 92378 184756 352716 646646 1144066 1 12 78 364 1365 4368 12376 31824 75582 167960 352716 705432 1352078 2496144 1 13 91 455 1820 6188 18564 50388 125970 293930 646646 1352078 2704156 5200300 1 14 105 560 2380 8568 27132 77520 203490 497420 1144066 2496144 5200300 10400600 1 15 120 680 3060 11628 38760 116280 319770 817190 1961256 4457400 9657700 20058300 1 16 136 816 3876 15504 54264 170544 490314 1307504 3268760 7726160 17383860 37442160 Columns 15 through 16 1 1 15 16 120 136 680 816 3060 3876 11628 15504 38760 54264 116280 170544 319770 490314 817190 1307504 1961256 3268760 4457400 7726160 9657700 17383860 20058300 37442160 40116600 77558760 77558760 155117520

Assertion failed.