Cody

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

Solution 109726

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

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

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.000289 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.000270 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.004949 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!