Cody

# Problem 42695. Replace secondary diagonal elements of a square array

Solution 1765935

Submitted on 28 Mar 2019 by Abdelfatah Teamah
• Size: 8
• This is the leading solution.
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
A = [1 2 3; 4 5 6; 7 8 9]; n = 10; B_correct = [1 2 10; 4 10 6; 10 8 9]; assert(isequal(sec_diag_replacement(A,n),B_correct))

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In sec_diag_replacement (line 2) In ScoringEngineTestPoint1 (line 4) In solutionTest (line 3)]

2   Pass
A = 1; n = 10; B_correct = 10; assert(isequal(sec_diag_replacement(A,n),B_correct))

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In sec_diag_replacement (line 2) In ScoringEngineTestPoint2 (line 4) In solutionTest (line 5)]

3   Pass
A = ones(4); n = 0; B_correct = [1 1 1 0; 1 1 0 1; 1 0 1 1; 0 1 1 1]; assert(isequal(sec_diag_replacement(A,n),B_correct))

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In sec_diag_replacement (line 2) In ScoringEngineTestPoint3 (line 4) In solutionTest (line 7)]

4   Pass
A = eye(4); n = 10; B_correct = [1 0 0 10; 0 1 10 0; 0 10 1 0; 10 0 0 1]; assert(isequal(sec_diag_replacement(A,n),B_correct))

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In sec_diag_replacement (line 2) In ScoringEngineTestPoint4 (line 4) In solutionTest (line 9)]

5   Pass
A = [1 1 2 1; 1 2 1 1; 2 1 1 1; 1 1 1 2]; n = 3; B_correct = [1 1 2 3; 1 2 3 1; 2 3 1 1; 3 1 1 2]; assert(isequal(sec_diag_replacement(A,n),B_correct))

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In sec_diag_replacement (line 2) In ScoringEngineTestPoint5 (line 4) In solutionTest (line 11)]

6   Pass
A = zeros(3); n = -1; B_correct = [0 0 -1; 0 -1 0; -1 0 0]; assert(isequal(sec_diag_replacement(A,n),B_correct))

[Warning: Function assert has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In unix (line 32) In sec_diag_replacement (line 2) In ScoringEngineTestPoint6 (line 4) In solutionTest (line 13)]