Cody

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

Solution 550535

Submitted on 29 Dec 2014 by rifat
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 = 11 13 14 10 1 12 15 3 9 2 7 16 5 8 4 6 M_out = 11 1 9 5 13 12 2 8 14 15 7 4 10 3 16 6

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

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.000428 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.000412 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.016984 seconds.