Cody

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

Solution 875181

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

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.001397 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.000915 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.006369 seconds.

Community Treasure Hunt

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

Start Hunting!