Given an integer n, make an n-by-n matrix as shown below. The a(1,1) should be 0. As we move away from the top-left, the number increase by 1, until we hit a diagonal, where all the elements are (n-1) along the diagonal. After passing diagonal, the number increases by 1 each time.
This is a follow-up question to Cody Challenge CheckerBoard Problem at https://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix
For n=10
Input n = 10 Output a is [0 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 8 2 3 4 5 6 7 8 9 8 7 3 4 5 6 7 8 9 8 7 6 4 5 6 7 8 9 8 7 6 5 5 6 7 8 9 8 7 6 5 4 6 7 8 9 8 7 6 5 4 3 7 8 9 8 7 6 5 4 3 2 8 9 8 7 6 5 4 3 2 1 9 8 7 6 5 4 3 2 1 0]
Solution Stats
Problem Comments
1 Comment
Solution Comments
Show comments
Loading...
Problem Recent Solvers90
Suggested Problems
-
6086 Solvers
-
Swap the first and last columns
22631 Solvers
-
Find the peak 3n+1 sequence value
2568 Solvers
-
Set some matrix elements to zero
626 Solvers
-
Get the elements of diagonal and antidiagonal for any m-by-n matrix
513 Solvers
More from this Author9
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Additional test cases have been added.