Cody

# Problem 738. Criss_Cross_010 : Unique elements, Square array, Words in one array

Solution 1564609

Submitted on 19 Jun 2018 by J. S. Kowontan
• Size: 32
• This is the leading solution.
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,:); vc=M(:,1:n); w=[vr;vc']; w=sortrows(w); M_out=Criss_Cross(w) assert(isequal(M,M_out)||isequal(M',M_out));

M = 4 9 15 3 5 13 7 16 14 12 8 11 10 1 6 2 M_out = 4 9 15 3 5 13 7 16 14 12 8 11 10 1 6 2

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,:); vc=M(:,1:n); w=[vr;vc']; w=sortrows(w); M_out=Criss_Cross(w) assert(isequal(M,M_out)||isequal(M',M_out));

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

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

Elapsed time is 0.000442 seconds.

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

Elapsed time is 0.000396 seconds.

5   Pass
n=256; % Create a Unique element square array M=randperm(n*n); M=reshape(M,n,n); vr=M(1:n,:); vc=M(:,1:n); w=[vr;vc']; w=sortrows(w); tic M_out=Criss_Cross(w); toc assert(isequal(M,M_out)||isequal(M',M_out));

Elapsed time is 0.117284 seconds.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!