Cody

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

Solution 726014

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

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

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.001750 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.001752 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.033629 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!