MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Solution 83592

Submitted on 29 Apr 2012 by Richard Zapor

Correct

174Size
`This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.`

Test Suite

Test
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]));
```