Cody

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

Solution 109730

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

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.000595 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.000559 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.006603 seconds.

Suggested Problems

More from this Author246

Community Treasure Hunt

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

Start Hunting!