Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 311398

Submitted on 27 Aug 2013 by Wolfgang Schwanghart

Correct

25Size
Leading solution size is 19.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
n=1;
p=1;
assert(isequal(pascalp(n),p))

                    
2
Pass
 
%%
n=3;
p=[1 2 1;2 4 2;1 2 1];
assert(isequal(pascalp(n),p))
ans =
     1     1
     1     1
ans =
     1     2     1
     2     4     2
     1     2     1
3
Pass
 
%%
n=5;
p=[1 4 6 4 1;4 16 24 16 4;6 24 36 24 6;4 16 24 16 4;1 4 6 4 1];
assert(isequal(pascalp(n),p))
ans =
     1     1
     1     1
ans =
     1     2     1
     2     4     2
     1     2     1
ans =
     1     3     3     1
     3     9     9     3
     3     9     9     3
     1     3     3     1
ans =
     1     4     6     4     1
     4    16    24    16     4
     6    24    36    24     6
     4    16    24    16     4
     1     4     6     4     1
4
Pass
 
%%
n=8;
p=[1 7 21 35 35 21 7 1;7 49 147 245 245 147 49 7;21 147 441 735 735 441 147 21;35 245 735 1225 1225 735 245 35;35 245 735 1225 1225 735 245 35;21 147 441 735 735 441 147 21;7 49 147 245 245 147 49 7;1 7 21 35 35 21 7 1];
assert(isequal(pascalp(n),p))
ans =
     1     1
     1     1
ans =
     1     2     1
     2     4     2
     1     2     1
ans =
     1     3     3     1
     3     9     9     3
     3     9     9     3
     1     3     3     1
ans =
     1     4     6     4     1
     4    16    24    16     4
     6    24    36    24     6
     4    16    24    16     4
     1     4     6     4     1
ans =
     1     5    10    10     5     1
     5    25    50    50    25     5
    10    50   100   100    50    10
    10    50   100   100    50    10
     5    25    50    50    25     5
     1     5    10    10     5     1
ans =
     1     6    15    20    15     6     1
     6    36    90   120    90    36     6
    15    90   225   300   225    90    15
    20   120   300   400   300   120    20
    15    90   225   300   225    90    15
     6    36    90   120    90    36     6
     1     6    15    20    15     6     1
ans =
           1           7          21          35          35          21           7           1
           7          49         147         245         245         147          49           7
          21         147         441         735         735         441         147          21
          35         245         735        1225        1225         735         245          35
          35         245         735        1225        1225         735         245          35
          21         147         441         735         735         441         147          21
           7          49         147         245         245         147          49           7
           1           7          21          35          35          21           7           1