Cody

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

Solution 1671190

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

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

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.001024 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.000952 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.031036 seconds.

Suggested Problems

More from this Author241

Community Treasure Hunt

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

Start Hunting!