Cody

# Problem 44490. Vector pop

Solution 2275257

Submitted on 12 May 2020 by Shahar Kalfon
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   Pass
v = [1, 2, 7]; n = 0; [v, w] = pop(v, n); v_correct = [1, 2, 7]; assert(isequal(v, v_correct)); assert(isempty(w));

v1 = 1 2 7 o = 3 z = 3 q = 4 v = 1 2 7 w = 1×0 empty double row vector

3   Pass
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));

v1 = 1 2 3 4 5 6 7 8 9 10 o = 10 z = 7 q = 8 v = 1 2 3 4 5 6 7 w = 8 9 10

4   Pass
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 v = 1 2 3 v1 = 1 2 3 o = 3 ans = logical 1 w = 1 2 3 v = [] v = [] w = 1 2 3

5   Pass
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));

v = 1 1 1 1 1 1 1 1 1 1 v1 = 1 1 1 1 1 1 1 1 1 1 o = 10 z = -3 q = -2 v = 1 1 1 1 1 1 w = 1 1 1 1 v = 1 1 1 1 1 1 w = 1 1 1 1

6   Pass
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));

v1 = 0 0 0 0 0 0 0 0 o = 8 z = 6 q = 7 v = 0 0 0 0 0 0 w = 0 0

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!