Cody

Solution 552886

Submitted on 6 Jan 2015 by Alfonso Nieto-Castanon
  • Size: 14
  • This is the leading solution.
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
%% a = ones(3) - eye(3); b = zeros(3); mat = [a b; b a]; n = 2; assert(isequal(cComponents(mat),n))

2   Pass
%% a = randi(20); mat = ones(a) - eye(a); n = 1; assert(isequal(cComponents(mat),n))

3   Pass
%% mat = [0 1 0 0 1; 1 0 1 0 0; 0 1 0 1 0; 0 0 1 0 1; 1 0 0 1 0]; assert(isequal(cComponents(mat),1))

4   Pass
%% a = ones(3) - eye(3); b = zeros(3); mat = [a b b; b a b; b b a]; n = 3; assert(isequal(cComponents(mat),n))

5   Pass
%% a = ones(3) - eye(3); b = zeros(3); p = floor((randi(20)+3)/3)*3; mat = []; for i= 1:p c = [repmat(b,1,i-1) a repmat(b,1,p-i)]; mat = [mat;c]; end assert(isequal(cComponents(mat),p))