Given an integer n >= 0, generate the length n+1 row vector representing the n-th row of Pascal's Triangle.
Examples:
pascalTri(0) ans = 1
pascalTri(1) ans = 1 1
pascalTri(2) ans = 1 2 1
the last assertion is wrong
Oops, I guess I commented in the solution, not the problem. (What's the difference????) They should check if their answer is symmetrical, which it isn't, so their solution must be wrong regardless of subsequent values
I've removed the last assertion and rescored. Thanks for the note.
fun!
a nice one-liner, again
Easy, but I enjoyed it nevertheless.
Used expm but the numbers didn't equal until I wrapped with int16.
using convolution
Size is 26. How do you get any less?
"y = arrayfun(@nchoosek, repmat(n, 1, n + 1), 0:n)" gives a score of 23
Good Qeustion
Why won't syms work? I can run this in MATLAB and it outputs the correct pascal line given n.
using cell
We used a subfunction Cpn(n,p)
Y=factorial(p)/(factorial(n)*factorial(p-n)) instead of the function "nchoosek" .
When I submitted the solution "y=round((2^n)*binopdf(0:n,n,0.5));" cody test aborted by saying "binopdf" is an undefined function. Strange !!
binopdf is part of the statistics toolbox, not core Matlab.
How about an assertion on whether or not the sides are symmetric?
This problem's last assertion is wrong :/
isequal(correct(1:27),correct(54:-1:28))
At first I thought it was an issue with accuracy on my end ...
Determine whether a vector is monotonically increasing
8792 Solvers
Sum of first n terms of a harmonic progression
165 Solvers
Return the first and last character of a string
1396 Solvers
334 Solvers
150 Solvers