a bit faster (median t=0.56s for 31
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
n=32;
[vr]=solve_PerfectSqr_Seq(n);
% Verification of solutions for 32 thru 51
Tests=[1 1 1]; % start in Pass : Looks for fails
if n<33
sqrs=[4 9 16 25 36 49];
elseif n<41
sqrs=[4 9 16 25 36 49 64];
elseif n<51
sqrs=[4 9 16 25 36 49 64 81];
else % valid up thru n=61
sqrs=[4 9 16 25 36 49 64 81 100];
end
if isempty(vr)
Tests=[0 0 0];
else
% Check use all 1 thru 32
if length(unique(vr))~=n || max(vr)>n || min(vr)<1, Tests(1)=0;end
% Check Squareness
for i=1:length(vr)-1
if isempty(intersect(vr(i)+vr(i+1),sqrs))
Tests(2)=0;
end
end
% Check Ends Squareness
if isempty(intersect(vr(1)+vr(length(vr)),sqrs)),Tests(3)=0;end
end
assert(isequal(Tests,[1 1 1]));
|
2 | Pass |
%%
n=33;
[vr]=solve_PerfectSqr_Seq(n);
% Verification of solutions for 32 thru 51
Tests=[1 1 1]; % start in Pass : Looks for fails
if n<33
sqrs=[4 9 16 25 36 49];
elseif n<41
sqrs=[4 9 16 25 36 49 64];
elseif n<51
sqrs=[4 9 16 25 36 49 64 81];
else % valid up thru n=61
sqrs=[4 9 16 25 36 49 64 81 100];
end
if isempty(vr)
Tests=[0 0 0];
else
% Check use all 1 thru 32
if length(unique(vr))~=n || max(vr)>n || min(vr)<1, Tests(1)=0;end
% Check Squareness
for i=1:length(vr)-1
if isempty(intersect(vr(i)+vr(i+1),sqrs))
Tests(2)=0;
end
end
% Check Ends Squareness
if isempty(intersect(vr(1)+vr(length(vr)),sqrs)),Tests(3)=0;end
end
assert(isequal(Tests,[1 1 1]));
|
3 | Pass |
%%
n=41;
[vr]=solve_PerfectSqr_Seq(n);
% Verification of solutions for 32 thru 51
Tests=[1 1 1]; % start in Pass : Looks for fails
if n<33
sqrs=[4 9 16 25 36 49];
elseif n<41
sqrs=[4 9 16 25 36 49 64];
elseif n<51
sqrs=[4 9 16 25 36 49 64 81];
else % valid up thru n=61
sqrs=[4 9 16 25 36 49 64 81 100];
end
if isempty(vr)
Tests=[0 0 0];
else
% Check use all 1 thru 32
if length(unique(vr))~=n || max(vr)>n || min(vr)<1, Tests(1)=0;end
% Check Squareness
for i=1:length(vr)-1
if isempty(intersect(vr(i)+vr(i+1),sqrs))
Tests(2)=0;
end
end
% Check Ends Squareness
if isempty(intersect(vr(1)+vr(length(vr)),sqrs)),Tests(3)=0;end
end
assert(isequal(Tests,[1 1 1]));
|
Back to basics 22 - Rotate a matrix
763 Solvers
579 Solvers
697 Solvers
Given a window, how many subsets of a vector sum positive
743 Solvers
Reverse the elements of an array
687 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!