Cody

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

Solution 172805

Submitted on 5 Dec 2012 by @bmtran (Bryant Tran)
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 = 6 14 4 15 5 3 11 1 9 8 13 16 7 12 2 10 Elapsed time is 0.095424 seconds. M_out = 6 14 4 15 5 3 11 1 9 8 13 16 7 12 2 10

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

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.000759 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.007511 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.190885 seconds.