Cody

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

Solution 726013

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,:); 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 = 12 14 8 1 7 2 15 13 11 4 3 6 9 16 10 5 M_out = 12 7 11 9 14 2 4 16 8 15 3 10 1 13 6 5

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

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.000212 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.000237 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.002245 seconds.