Cody

# Problem 737. Criss_Cross_000 : Unique elements in a Square array

Solution 726005

Submitted on 31 Aug 2015 by Binbin Qi
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
%% format long format compact seed=clock; seed=1000*seed(6); rng(seed) n=4; % Create a Unique element square array M=randperm(n*n); M=reshape(M,n,n) vr=M(1:n,:); vr=sortrows(vr); vc=M(:,1:n); vc=sortrows(vc')'; tic M_out=Criss_Cross(vr,vc); toc M_out assert(isequal(M,M_out));

M = 11 4 1 15 10 8 12 2 16 5 6 7 3 13 14 9 Elapsed time is 0.000805 seconds. M_out = 11 4 1 15 10 8 12 2 16 5 6 7 3 13 14 9

2   Pass
%% seed=clock; seed=1000*seed(6); rng(seed) n=8; % Create a Unique element square array M=randperm(n*n); M=reshape(M,n,n) vr=M(1:n,:); vr=sortrows(vr); vc=M(:,1:n); vc=sortrows(vc')'; tic M_out=Criss_Cross(vr,vc); toc M_out assert(isequal(M,M_out));

M = 37 55 54 24 41 53 44 20 19 33 49 42 7 58 25 63 14 35 1 17 23 16 52 8 9 5 3 27 36 10 21 13 62 46 56 15 45 40 30 47 32 31 12 34 59 18 60 48 38 57 29 28 50 22 26 11 39 61 6 2 51 43 64 4 Elapsed time is 0.000047 seconds. M_out = 37 55 54 24 41 53 44 20 19 33 49 42 7 58 25 63 14 35 1 17 23 16 52 8 9 5 3 27 36 10 21 13 62 46 56 15 45 40 30 47 32 31 12 34 59 18 60 48 38 57 29 28 50 22 26 11 39 61 6 2 51 43 64 4

3   Pass
%% seed=clock; seed=1000*seed(6); rng(seed) n=128; % Create a Unique element square array M=randperm(n*n); M=reshape(M,n,n); vr=M(1:n,:); vr=sortrows(vr); vc=M(:,1:n); vc=sortrows(vc')'; tic M_out=Criss_Cross(vr,vc); toc assert(isequal(M,M_out));

Elapsed time is 0.000125 seconds.

4   Pass
%% seed=clock; seed=1000*seed(6); rng(seed) n=1024; % Create a Unique element square array M=randperm(n*n); M=reshape(M,n,n); vr=M(1:n,:); vr=sortrows(vr); vc=M(:,1:n); vc=sortrows(vc')'; tic M_out=Criss_Cross(vr,vc); toc assert(isequal(M,M_out));

Elapsed time is 0.004933 seconds.

5   Pass
%% seed=clock; seed=1000*seed(6); rng(seed) n=4096; % Create a Unique element square array M=randperm(n*n); M=reshape(M,n,n); vr=M(1:n,:); vr=sortrows(vr); vc=M(:,1:n); vc=sortrows(vc')'; tic M_out=Criss_Cross(vr,vc); toc assert(isequal(M,M_out));

Elapsed time is 0.224826 seconds.