This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.
This solution is outdated. To rescore this solution, sign in.
I am new to MATLAB and this was first problem I created. So happy to see variety of solutions I could not think of! Thanks and enjoy coding!
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
n = 3;
a_correct = [0 1 2;
1 2 1;
2 1 0];
assert(isequal(rainBowMatrix(n),a_correct))
h =
0 1 2
1 2 -1
2 -1 -1
t =
0 1 2
1 2 1
2 1 0
|
2 | Pass |
n = 8;
a_correct = [0 1 2 3 4 5 6 7;
1 2 3 4 5 6 7 6;
2 3 4 5 6 7 6 5;
3 4 5 6 7 6 5 4;
4 5 6 7 6 5 4 3;
5 6 7 6 5 4 3 2;
6 7 6 5 4 3 2 1;
7 6 5 4 3 2 1 0];
assert(isequal(rainBowMatrix(n),a_correct))
h =
0 1 2 3 4 5 6 7
1 2 3 4 5 6 7 -1
2 3 4 5 6 7 -1 -1
3 4 5 6 7 -1 -1 -1
4 5 6 7 -1 -1 -1 -1
5 6 7 -1 -1 -1 -1 -1
6 7 -1 -1 -1 -1 -1 -1
7 -1 -1 -1 -1 -1 -1 -1
t =
0 1 2 3 4 5 6 7
1 2 3 4 5 6 7 6
2 3 4 5 6 7 6 5
3 4 5 6 7 6 5 4
4 5 6 7 6 5 4 3
5 6 7 6 5 4 3 2
6 7 6 5 4 3 2 1
7 6 5 4 3 2 1 0
|
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!