Cody

# Problem 44490. Vector pop

Solution 1850201

Submitted on 16 Jun 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('pop.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')

2   Fail
v = [1, 2, 7]; n = 0; [v, w] = pop(v, n); v_correct = [1, 2, 7]; assert(isequal(v, v_correct)); assert(isempty(w));

len = 3

Index in position 1 exceeds array bounds (must not exceed 1). Error in pop (line 3) w = v(len-n+1,len); Error in Test2 (line 3) [v, w] = pop(v, n);

3   Fail
v = 1:10; n = 3; [v, w] = pop(v, n); v_correct = 1:7; w_correct = 8:10; assert(isequal(v, v_correct)); assert(isequal(w, w_correct));

len = 10

Index in position 1 exceeds array bounds (must not exceed 1). Error in pop (line 3) w = v(len-n+1,len); Error in Test3 (line 3) [v, w] = pop(v, n);

4   Fail
v = [1; 2; 3] n = 5; [v, w] = pop(v, n); w_correct = [1; 2; 3]; assert(isempty(v)); assert(isequal(w, w_correct));

v = 1 2 3 len = 3

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in pop (line 3) w = v(len-n+1,len); Error in Test4 (line 3) [v, w] = pop(v, n);

5   Fail
v = ones(10, 1); n = 4; [v, w] = pop(v, n); v_correct = ones(6, 1); w_correct = ones(4, 1); assert(isequal(v, v_correct)); assert(isequal(w, w_correct));

len = 10

Index in position 2 exceeds array bounds (must not exceed 1). Error in pop (line 3) w = v(len-n+1,len); Error in Test5 (line 3) [v, w] = pop(v, n);

6   Fail
v = zeros(1, 8); n = 2; [v, w] = pop(v, n); v_correct = zeros(1, 6); w_correct = zeros(1, 2); assert(isequal(v, v_correct)); assert(isequal(w, w_correct));

len = 8

Index in position 1 exceeds array bounds (must not exceed 1). Error in pop (line 3) w = v(len-n+1,len); Error in Test6 (line 3) [v, w] = pop(v, n);