Cody

# Problem 42631. Cumulative minimum of an array

Solution 1944099

Submitted on 20 Sep 2019
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')))

Index exceeds the number of array elements (0). Error in cumin (line 5) main = main(1); 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')))

75 70 70 66 29 29 12 12 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Array indices must be positive integers or logical values. Error in cumin (line 9) main=varargin{end-1} Error in Test3 (line 3) assert(isequal(cumin(x,1),cummin(x,1)))

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')))

85 1 1 1 1 1 1

Array indices must be positive integers or logical values. Error in cumin (line 9) main=varargin{end-1} Error in Test4 (line 3) assert(isequal(cumin(x,1),cummin(x,1)))

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')))

92 99 1 8 15 67 74 51 58 40 92 80 1 8 15 67 55 51 58 40 4 80 1 8 15 54 55 51 58 40 4 80 1 8 3 54 55 51 58 28 4 80 1 2 3 54 55 51 52 28 4 24 1 2 3 42 49 26 33 28 4 5 1 2 3 42 30 26 33 28 4 5 1 2 3 29 30 26 33 28 4 5 1 2 3 29 30 26 33 28 4 5 1 2 3 29 30 26 27 28

Array indices must be positive integers or logical values. Error in cumin (line 9) main=varargin{end-1} Error in Test5 (line 3) assert(isequal(cumin(x,1),cummin(x,1)))

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')))

Array indices must be positive integers or logical values. Error in cumin (line 9) main=varargin{end-1} Error in Test6 (line 3) assert(isequal(cumin(x,1),cummin(x,1)))