Cody

Problem 545. Flip the main diagonal of a matrix

Solution 2270897

Submitted on 11 May 2020
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   Fail
M=magic(5); y_correct = [9, 24,1,8 ,15; 23 ,21,7,14,16; ... 4,6,13,20,22; 10,12,19,5,3; 11,18,25,2,17]; assert(isequal(flipDiagonal(M),y_correct))

df = 9 21 13 5 17 r = 5 c = 5 M = 9 M = 9 0 0 21 M = 9 0 0 0 21 0 0 0 13 M = 9 0 0 0 0 21 0 0 0 0 13 0 0 0 0 5 M = 9 0 0 0 0 0 21 0 0 0 0 0 13 0 0 0 0 0 5 0 0 0 0 0 17 y = 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9

Assertion failed.

2   Fail
M=magic(2); y_correct=[2 3; 4 1]; assert(isequal(flipDiagonal(M),y_correct))

df = 2 1 r = 2 c = 2 M = 2 M = 2 0 0 1 y = 1 3 4 2

Assertion failed.

3   Fail
M=ones(4); M(2,2)=4; M(3,3)=9; M(4,4)=16; y_correct=ones(4); y_correct(1,1)=16; y_correct(2,2)=9; y_correct(3,3)=4; assert(isequal(flipDiagonal(M),y_correct))

df = 16 9 4 1 r = 4 c = 4 M = 16 M = 16 0 0 9 M = 16 0 0 0 9 0 0 0 4 M = 16 0 0 0 0 9 0 0 0 0 4 0 0 0 0 1 y = 1 1 1 1 1 4 1 1 1 1 9 1 1 1 1 16

Assertion failed.

4   Pass
M=[1]; y_correct=[1]; assert(isequal(flipDiagonal(M),y_correct))

df = 1 r = 1 c = 1 M = 1 y = 1

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

df = 25 19 13 7 1 r = 5 c = 5 M = 25 M = 25 0 0 19 M = 25 0 0 0 19 0 0 0 13 M = 25 0 0 0 0 19 0 0 0 0 13 0 0 0 0 7 M = 25 0 0 0 0 0 19 0 0 0 0 0 13 0 0 0 0 0 7 0 0 0 0 0 1 y = 1 6 11 16 21 2 7 12 17 22 3 8 13 18 23 4 9 14 19 24 5 10 15 20 25

Assertion failed.

6   Fail
M=[1,1,1,1;2,2,2,2;3,3,3,3;4,4,4,4]; y_correct=[4,1,1,1;2,3,2,2;3,3,2,3;4,4,4,1]; assert(isequal(flipDiagonal(M),y_correct))

df = 4 3 2 1 r = 4 c = 4 M = 4 M = 4 0 0 3 M = 4 0 0 0 3 0 0 0 2 M = 4 0 0 0 0 3 0 0 0 0 2 0 0 0 0 1 y = 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4

Assertion failed.