Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%% summation
assert(isequal(foldl(@plus, 0, 1:100), 5050));
|
2 | Pass |
%% summation 2
r = rand(1, 100);
y = foldl(@plus, 0, r);
yc = sum(r);
assert(abs(y - yc)/abs(y) < 1e-6);
|
3 | Pass |
%% factorial
assert(isequal(foldl(@times, 1, 1:15), factorial(15)));
|
4 | Fail |
%% find maximum
r = rand(1, 1000);
assert(isequal(foldl(@max, -Inf, r), max(r)));
Error: Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer.
|
5 | Pass |
%%
assert(isequal(foldl(@(x_, y_) 2*x_ + y_, 4, 1:3), 43));
|
6 | Pass |
%% handle 1
sumplusfive = foldl(@plus, 5);
assert(isequal(sumplusfive(1:100), 5055));
|
7 | Pass |
%% handle 2
concat = foldl(@(x_, y_) [x_ y_]);
r1 = rand(1, 10);
r2 = rand(1, 10);
assert(isequal(concat(r1, r2), [r1 r2]));
|
Project Euler: Problem 7, Nth prime
521 Solvers
Back to basics 21 - Matrix replicating
1052 Solvers
Create a vector whose elements depend on the previous element
391 Solvers
Split a string into chunks of specified length
475 Solvers
250 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!