Cody

Problem 43117. 2D Indexes

Solution 1260650

Submitted on 1 Sep 2017
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
P = 1; y_correct =[0,0]; assert(isequal(index2(P),y_correct))

Error using dec2base (line 25) Second argument must be an integer, 2 <= B <= 36. Error in index2 (line 2) sortrows(dec2base(0:P^2-1,P)-'0','descend'); Error in Test1 (line 3) assert(isequal(index2(P),y_correct))

2   Pass
P = 2; y_correct =[0,0;1,0;0,1]; assert(isequal(index2(P),y_correct))

3   Pass
P=3; y_correct=[0, 0;... 1, 0;... 0, 1;... 2, 0;... 1, 1;... 0, 2;... ]; assert(isequal(index2(P),y_correct))

4   Pass
P=5; y_correct=[0, 0;... 1, 0;... 0, 1;... 2, 0;... 1, 1;... 0, 2;... 3, 0;... 2, 1;... 1, 2;... 0, 3;... 4, 0;... 3, 1;... 2, 2;... 1, 3;... 0, 4;... ]; assert(isequal(index2(P),y_correct))