Cody

Problem 42631. Cumulative minimum of an array

Solution 2406703

Submitted on 28 May 2020
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
filetext = fileread('cumin.m'); assert(isempty(strfind(filetext,'cummin'))) assert(isempty(strfind(filetext,'cummax'))) assert(isempty(strfind(filetext,'feval')))

2   Fail
x = randi(100); assert(isequal(cumin(x),cummin(x))) assert(isequal(cumin(x,1),cummin(x,1))) assert(isequal(cumin(x,2),cummin(x,2))) assert(isequal(cumin(x,1,'reverse'),cummin(x,1,'reverse'))) assert(isequal(cumin(x,2,'reverse'),cummin(x,2,'reverse'))) assert(isequal(cumin(x,'reverse'),cummin(x,'reverse')))

Error using size Dimension argument must be a positive integer scalar or a vector of positive integers. Error in cumin (line 11) for j = 2:size(x,d) Error in Test2 (line 2) assert(isequal(cumin(x),cummin(x)))

3   Fail
x = randi(100,randi([2 100]),1); assert(isequal(cumin(x),cummin(x))) assert(isequal(cumin(x,1),cummin(x,1))) assert(isequal(cumin(x,2),cummin(x,2))) assert(isequal(cumin(x,1,'reverse'),cummin(x,1,'reverse'))) assert(isequal(cumin(x,2,'reverse'),cummin(x,2,'reverse'))) assert(isequal(cumin(x,'reverse'),cummin(x,'reverse')))

Error using size Dimension argument must be a positive integer scalar or a vector of positive integers. Error in cumin (line 11) for j = 2:size(x,d) Error in Test3 (line 7) assert(isequal(cumin(x,'reverse'),cummin(x,'reverse')))

4   Fail
x = randi(100,1,randi([2 100])); assert(isequal(cumin(x),cummin(x))) assert(isequal(cumin(x,1),cummin(x,1))) assert(isequal(cumin(x,2),cummin(x,2))) assert(isequal(cumin(x,1,'reverse'),cummin(x,1,'reverse'))) assert(isequal(cumin(x,2,'reverse'),cummin(x,2,'reverse'))) assert(isequal(cumin(x,'reverse'),cummin(x,'reverse')))

Error using size Dimension argument must be a positive integer scalar or a vector of positive integers. Error in cumin (line 11) for j = 2:size(x,d) Error in Test4 (line 7) assert(isequal(cumin(x,'reverse'),cummin(x,'reverse')))

5   Fail
x = magic(10); assert(isequal(cumin(x),cummin(x))) assert(isequal(cumin(x,1),cummin(x,1))) assert(isequal(cumin(x,2),cummin(x,2))) assert(isequal(cumin(x,1,'reverse'),cummin(x,1,'reverse'))) assert(isequal(cumin(x,2,'reverse'),cummin(x,2,'reverse'))) assert(isequal(cumin(x,'reverse'),cummin(x,'reverse')))

Error using size Dimension argument must be a positive integer scalar or a vector of positive integers. Error in cumin (line 11) for j = 2:size(x,d) Error in Test5 (line 7) assert(isequal(cumin(x,'reverse'),cummin(x,'reverse')))

6   Fail
x = []; assert(isequal(cumin(x),cummin(x))) assert(isequal(cumin(x,1),cummin(x,1))) assert(isequal(cumin(x,2),cummin(x,2))) assert(isequal(cumin(x,1,'reverse'),cummin(x,1,'reverse'))) assert(isequal(cumin(x,2,'reverse'),cummin(x,2,'reverse'))) assert(isequal(cumin(x,'reverse'),cummin(x,'reverse')))

Error using size Dimension argument must be a positive integer scalar or a vector of positive integers. Error in cumin (line 11) for j = 2:size(x,d) Error in Test6 (line 2) assert(isequal(cumin(x),cummin(x)))