Cody

# Problem 43682. Pairwise column flip

Solution 1721909

Submitted on 6 Feb 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
x = 1; y_correct = 1; assert(isequal(flip_columns(x),y_correct))

2   Fail
x = 1:5; y_correct = [2 1 4 3 5]; assert(isequal(flip_columns(x),y_correct))

Error using vertcat Dimensions of arrays being concatenated are not consistent. Error in flip_columns (line 2) y = reshape([x(:,2:2:end);x(:,1:2:end)],size(x)); Error in Test2 (line 3) assert(isequal(flip_columns(x),y_correct))

3   Fail
x = [1 2 3 4 5]; y_correct = [2 1 4 3 5]; assert(isequal(flip_columns(x),y_correct))

Error using vertcat Dimensions of arrays being concatenated are not consistent. Error in flip_columns (line 2) y = reshape([x(:,2:2:end);x(:,1:2:end)],size(x)); Error in Test3 (line 3) assert(isequal(flip_columns(x),y_correct))

4   Pass
x = eye(4); y_correct = [0 1 0 0; 1 0 0 0; 0 0 0 1; 0 0 1 0]; assert(isequal(flip_columns(x),y_correct))

5   Fail
x = magic(5); y_correct = [24 17 8 1 15; ... 5 23 14 7 16; ... 6 4 20 13 22; ... 12 10 21 19 3; ... 18 11 2 25 9]; assert(isequal(flip_columns(x),y_correct))

Error using vertcat Dimensions of arrays being concatenated are not consistent. Error in flip_columns (line 2) y = reshape([x(:,2:2:end);x(:,1:2:end)],size(x)); Error in Test5 (line 7) assert(isequal(flip_columns(x),y_correct))