Problem 44063. Make a rainbow matrix (follow-up to checkerboard matrix)
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
goc3
on 31 Jul 2018
Additional test cases have been added.
Solution Comments
Show commentsGroup

Computational Geometry IV
- 20 Problems
- 12 Finishers
- Minimal cost
- Placing Beads Neatly in a Box
- Convex Hull Capture
- Find the sines of an isosceles triangle when given its area and height
- solid of revolution
- Height of a right-angled triangle
- solid of revolution
- Fun with a compass
- Height of a right-angled triangle
- Minimal cost
- Find the sides of an isosceles triangle when given its area and height from its base to apex
- Find the sines of an isosceles triangle when given its area and height
- Radiation Heat Transfer — View Factors (4)
- Radiation Heat Transfer — View Factors (5)
- The cake is a lie...
- Pancakes for everyone!
- Conic equation
- Why the heck are they blinking!?!?
- Find the Area of a Polygon
- Is It a Snake?
- Placing Beads Neatly in a Box
- Fun with a compass
- Angle bisectors
- Regular polygon bounded by and bounding a circle
- solid of revolution
- Height of a right-angled triangle
- Find the sides of an isosceles triangle when given its area and height from its base to apex
- Find the sines of an isosceles triangle when given its area and height
- Euclidean distance from a point to a polynomial
- Convex Hull Capture
- Under the sea: Snell's law & total internal reflection
Problem Recent Solvers71
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!