Cody

# Problem 44486. Vector push

Solution 1560969

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

2   Fail
v = [1, 2, 7]; x = []; [v, n] = push(v, x); v_correct = [1, 2, 7]; n_correct = 3; assert(isequal(v, v_correct)); assert(isequal(n, n_correct));

Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-0. Error in push (line 13) v(t+1,t+r)=x; Error in Test2 (line 3) [v, n] = push(v, x);

3   Fail
v = []; x = [5, 6, 8]; [v, n] = push(v, x); v_correct = [5, 6, 8]; n_correct = 3; assert(isequal(v, v_correct)); assert(isequal(n, n_correct));

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. Error in push (line 13) v(t+1,t+r)=x; Error in Test3 (line 3) [v, n] = push(v, x);

4   Fail
v = []; x = [7; 3; 9; 4]; [v, n] = push(v, x); v_correct = [7; 3; 9; 4]; n_correct = 4; assert(isequal(v, v_correct)); assert(isequal(n, n_correct));

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. Error in push (line 13) v(t+1,t+r)=x; Error in Test4 (line 3) [v, n] = push(v, x);

5   Fail
v1 = randi(10, 1, 5); x = 5; [v, n] = push(v1, x); v_correct = [v1, 5]; n_correct = 6; assert(isequal(v, v_correct)); assert(isequal(n, n_correct));

Assertion failed.

6   Fail
v = [ones(4, 1)]; x = [3, 5]; [v, n] = push(v, x); v_correct = [1; 1; 1; 1; 3; 5]; n_correct = 6; assert(isequal(v, v_correct)); assert(isequal(n, n_correct));

Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 2-by-1. Error in push (line 13) v(t+1,t+r)=x; Error in Test6 (line 3) [v, n] = push(v, x);

7   Fail
v = [zeros(1, 4)]; x = [3; 0]; [v, n] = push(v, x); v_correct = [0, 0, 0, 0, 3, 0]; n_correct = 6; assert(isequal(v, v_correct)); assert(isequal(n, n_correct)); v = [8, 2]; x = []; [v, n] = push(v, x); v_correct = [8, 2]; n_correct = 2; assert(isequal(v, v_correct)); assert(isequal(n, n_correct));

Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-2. Error in push (line 13) v(t+1,t+r)=x; Error in Test7 (line 3) [v, n] = push(v, x);

### Community Treasure Hunt

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

Start Hunting!