Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 352972

Submitted on 16 Nov 2013 by Alfonso Nieto-Castanon

Correct

10000Size
Leading solution size is 300.
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
 
%%
feval(@assignin,'caller','score',0);

                    
2
Pass
 
%%
%urlwrite('http://tinyurl.com/matlab-Knots','Knots_sample.mat')
urlwrite('http://rmatlabtest.appspot.com/testsuite_sample_knots.mat','Knots_sample.mat');

                    
3
Pass
 
%%
eKnots=[94 50 1719 11390 18 3446 7402 669 2558 13557 5376 25025 122 11566 2560 15726 7569 11728 35178 1872 972 29917 7433 2013 3 3081 1381 1424 1102 3534 2849 14520 16892 16553 18887 245 5729 3256 400 24811 290 15081 5679 12310 262 16317 1614 249 8782 192];
cases=4;
nKnots=zeros(cases,1);
KnotTime=zeros(cases,1);
rclock=clock;
rng(floor(rclock(6)*1000),'twister'); % Seed the random function
tKnots=randi(50,cases,1); % anti-code answer
load Knots_sample.mat
testsuite=suite; % update
for n=1:cases
 a=testsuite(tKnots(n)).a;
 xy=testsuite(tKnots(n)).xyIn;
 time0 = cputime;
  nKnots(n)=Knots(a,xy);
 KnotTime(n) = cputime - time0;
end
for n=1:cases
 assert(isequal(nKnots(n),eKnots(tKnots(n))),sprintf('Knot %i Was %i Expected %i',tKnots(n),nKnots(n),eKnots(tKnots(n))));
end
% Success: Report Times
P=[tKnots nKnots KnotTime]';
fprintf('Knot %i  Knots %i  Time %10.6f\n',P);
Knot 3  Knots 1719  Time   0.450000
Knot 36  Knots 245  Time   0.050000
Knot 41  Knots 290  Time   0.060000
Knot 5  Knots 18  Time   0.010000
4
Pass
 
%%
% Run for Time Score uses Knots [3 6 15 18 24 30 37 42 46 49]
eKnots=[94 50 1719 11390 18 3446 7402 669 2558 13557 5376 25025 122 11566 2560 15726 7569 11728 35178 1872 972 29917 7433 2013 3 3081 1381 1424 1102 3534 2849 14520 16892 16553 18887 245 5729 3256 400 24811 290 15081 5679 12310 262 16317 1614 249 8782 192];
cases=10;
nKnots=zeros(cases,1);
KnotTime=zeros(cases,1);
rclock=clock;
rng(floor(rclock(6)*1000),'twister'); % Seed the random function
%tKnots=randi(50,cases,1);
load Knots_sample.mat
testsuite=suite; % update
tKnots=[3 6 15 18 24 30 37 42 46 49]';
for n=1:cases
 a=testsuite(tKnots(n)).a;
 xy=testsuite(tKnots(n)).xyIn;
 time0 = cputime;
  nKnots(n)=Knots(a,xy);
 KnotTime(n) = cputime - time0;
end
for n=1:cases
 assert(isequal(nKnots(n),eKnots(tKnots(n))),sprintf('Knot %i Was %i Expected %i',tKnots(n),nKnots(n),eKnots(tKnots(n))));
end
% Success: Report Times
P=[tKnots nKnots KnotTime]';
fprintf('Knot %i  Knots %i  Time %10.6f\n',P);
% Score in msec
feval(@assignin,'caller','score',min(10000,floor(1000*sum(KnotTime))));
Knot 3  Knots 1719  Time   0.470000
Knot 6  Knots 3446  Time   0.690000
Knot 15  Knots 2560  Time   0.540000
Knot 18  Knots 11728  Time   1.130000
Knot 24  Knots 2013  Time   0.350000
Knot 30  Knots 3534  Time   0.650000
Knot 37  Knots 5729  Time   0.950000
Knot 42  Knots 15081  Time   3.330000
Knot 46  Knots 16317  Time   1.480000
Knot 49  Knots 8782  Time   0.700000