Cody

# Problem 1038. Change the sign of even index entries of the reversed vector

Solution 1590868

Submitted on 24 Jul 2018 by Srishti Saha
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
x = [4 -5 -2 9]; y_correct = [9 2 -5 -4]; assert(isequal(your_fcn_name(x),y_correct))

x_rev = 9 -2 -5 4 a = [] a_i = 9 a = 9 a_i = 2 a = 9 2 a_i = -5 a = 9 2 -5 a_i = -4 a = 9 2 -5 -4 y = 9 2 -5 -4

2   Pass
x = ones(1,4); y_correct = [1 -1 1 -1]; assert(isequal(your_fcn_name(x),y_correct))

x_rev = 1 1 1 1 a = [] a_i = 1 a = 1 a_i = -1 a = 1 -1 a_i = 1 a = 1 -1 1 a_i = -1 a = 1 -1 1 -1 y = 1 -1 1 -1

3   Pass
x = 1:10; y_correct = [10 -9 8 -7 6 -5 4 -3 2 -1]; assert(isequal(your_fcn_name(x),y_correct))

x_rev = 10 9 8 7 6 5 4 3 2 1 a = [] a_i = 10 a = 10 a_i = -9 a = 10 -9 a_i = 8 a = 10 -9 8 a_i = -7 a = 10 -9 8 -7 a_i = 6 a = 10 -9 8 -7 6 a_i = -5 a = 10 -9 8 -7 6 -5 a_i = 4 a = 10 -9 8 -7 6 -5 4 a_i = -3 a = 10 -9 8 -7 6 -5 4 -3 a_i = 2 a = 10 -9 8 -7 6 -5 4 -3 2 a_i = -1 a = 10 -9 8 -7 6 -5 4 -3 2 -1 y = 10 -9 8 -7 6 -5 4 -3 2 -1

4   Pass
x = 2:2:12; y_correct = [12 -10 8 -6 4 -2]; assert(isequal(your_fcn_name(x),y_correct))

x_rev = 12 10 8 6 4 2 a = [] a_i = 12 a = 12 a_i = -10 a = 12 -10 a_i = 8 a = 12 -10 8 a_i = -6 a = 12 -10 8 -6 a_i = 4 a = 12 -10 8 -6 4 a_i = -2 a = 12 -10 8 -6 4 -2 y = 12 -10 8 -6 4 -2

5   Pass
x = -3:3; y_correct = [3 -2 1 0 -1 2 -3]; assert(isequal(your_fcn_name(x),y_correct))

x_rev = 3 2 1 0 -1 -2 -3 a = [] a_i = 3 a = 3 a_i = -2 a = 3 -2 a_i = 1 a = 3 -2 1 a_i = 0 a = 3 -2 1 0 a_i = -1 a = 3 -2 1 0 -1 a_i = 2 a = 3 -2 1 0 -1 2 a_i = -3 a = 3 -2 1 0 -1 2 -3 y = 3 -2 1 0 -1 2 -3

6   Pass
x = [1 1 2 3 5 8 13 21 34 55 89 144]; y_correct = [144 -89 55 -34 21 -13 8 -5 3 -2 1 -1]; assert(isequal(your_fcn_name(x),y_correct))

x_rev = 144 89 55 34 21 13 8 5 3 2 1 1 a = [] a_i = 144 a = 144 a_i = -89 a = 144 -89 a_i = 55 a = 144 -89 55 a_i = -34 a = 144 -89 55 -34 a_i = 21 a = 144 -89 55 -34 21 a_i = -13 a = 144 -89 55 -34 21 -13 a_i = 8 a = 144 -89 55 -34 21 -13 8 a_i = -5 a = 144 -89 55 -34 21 -13 8 -5 a_i = 3 a = 144 -89 55 -34 21 -13 8 -5 3 a_i = -2 a = 144 -89 55 -34 21 -13 8 -5 3 -2 a_i = 1 a = 144 -89 55 -34 21 -13 8 -5 3 -2 1 a_i = -1 a = 144 -89 55 -34 21 -13 8 -5 3 -2 1 -1 y = 144 -89 55 -34 21 -13 8 -5 3 -2 1 -1

7   Pass
x = [1 0 1 0 1 0 1 0 1 0 1 0]; y_correct = [0 -1 0 -1 0 -1 0 -1 0 -1 0 -1]; assert(isequal(your_fcn_name(x),y_correct))

x_rev = 0 1 0 1 0 1 0 1 0 1 0 1 a = [] a_i = 0 a = 0 a_i = -1 a = 0 -1 a_i = 0 a = 0 -1 0 a_i = -1 a = 0 -1 0 -1 a_i = 0 a = 0 -1 0 -1 0 a_i = -1 a = 0 -1 0 -1 0 -1 a_i = 0 a = 0 -1 0 -1 0 -1 0 a_i = -1 a = 0 -1 0 -1 0 -1 0 -1 a_i = 0 a = 0 -1 0 -1 0 -1 0 -1 0 a_i = -1 a = 0 -1 0 -1 0 -1 0 -1 0 -1 a_i = 0 a = 0 -1 0 -1 0 -1 0 -1 0 -1 0 a_i = -1 a = 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1 y = 0 -1 0 -1 0 -1 0 -1 0 -1 0 -1

8   Pass
x = [0 1 0 2 0 3 0 4 0 5 0 6]; y_correct = [6 0 5 0 4 0 3 0 2 0 1 0]; assert(isequal(your_fcn_name(x),y_correct))

x_rev = 6 0 5 0 4 0 3 0 2 0 1 0 a = [] a_i = 6 a = 6 a_i = 0 a = 6 0 a_i = 5 a = 6 0 5 a_i = 0 a = 6 0 5 0 a_i = 4 a = 6 0 5 0 4 a_i = 0 a = 6 0 5 0 4 0 a_i = 3 a = 6 0 5 0 4 0 3 a_i = 0 a = 6 0 5 0 4 0 3 0 a_i = 2 a = 6 0 5 0 4 0 3 0 2 a_i = 0 a = 6 0 5 0 4 0 3 0 2 0 a_i = 1 a = 6 0 5 0 4 0 3 0 2 0 1 a_i = 0 a = 6 0 5 0 4 0 3 0 2 0 1 0 y = 6 0 5 0 4 0 3 0 2 0 1 0

9   Pass
x = [0 1 0 1 0 1 0 1 0 1 0 1]; y_correct = [x(2:end) x(1)]; assert(isequal(your_fcn_name(x),y_correct))

x_rev = 1 0 1 0 1 0 1 0 1 0 1 0 a = [] a_i = 1 a = 1 a_i = 0 a = 1 0 a_i = 1 a = 1 0 1 a_i = 0 a = 1 0 1 0 a_i = 1 a = 1 0 1 0 1 a_i = 0 a = 1 0 1 0 1 0 a_i = 1 a = 1 0 1 0 1 0 1 a_i = 0 a = 1 0 1 0 1 0 1 0 a_i = 1 a = 1 0 1 0 1 0 1 0 1 a_i = 0 a = 1 0 1 0 1 0 1 0 1 0 a_i = 1 a = 1 0 1 0 1 0 1 0 1 0 1 a_i = 0 a = 1 0 1 0 1 0 1 0 1 0 1 0 y = 1 0 1 0 1 0 1 0 1 0 1 0