Okay, so we can definitely do better than a for loop...
@Micah Beckman no, this solution is not an "efficient" answer even though it scores high... one should use sum(1:n) to replace a for loop sum.
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
n = 1;
t = 1;
assert(isequal(triangle(n),t))
t =
1
ans =
[]
|
2 | Pass |
%%
n = 3;
t = 6;
assert(isequal(triangle(n),t))
t =
6
ans =
[]
|
3 | Pass |
%%
n = 5;
t = 15;
assert(isequal(triangle(n),t))
t =
15
ans =
[]
|
4 | Pass |
%%
n = 30;
t = 465;
assert(isequal(triangle(n),t))
t =
465
ans =
[]
|
552 Solvers
244 Solvers
Return the first and last character of a string
1664 Solvers
Number of digits in an integer
272 Solvers
443 Solvers