Cody

# Problem 1135. Knots Contest: Minimum Knots (ContestSuite)

Solution 321932

Submitted on 22 Sep 2013 by Alfonso Nieto-Castanon
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
%% feval(@assignin,'caller','score',2000);

2   Pass
%% tic %urlwrite('http://tinyurl.com/matlab-KnotsContest','Knots_contest.mat') %urlwrite('http://tinyurl.com/matlab-numKnots','numKnots.m') % Fast numKnots urlwrite('http://rmatlabtest.appspot.com/testsuite_Contest_knots.mat','Knots_contest.mat') toc urlwrite('http://rmatlabtest.appspot.com/numKnots.m','numKnots.m') % Fast numKnots rehash path % Make numKnots.m available toc

ans = /users/msssystem4/Knots_contest.mat Elapsed time is 0.133119 seconds. ans = /users/msssystem4/numKnots.m [Warning: Function license has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In verifyCode>evaluateCode at 231 In verifyCode at 40 In fevalJSON at 14] [Warning: Function mex has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In verifyCode>evaluateCode at 231 In verifyCode at 40 In fevalJSON at 14] [Warning: Function home has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In verifyCode>evaluateCode at 231 In verifyCode at 40 In fevalJSON at 14] [Warning: Function keyboard has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In verifyCode>evaluateCode at 231 In verifyCode at 40 In fevalJSON at 14] [Warning: Function more has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In verifyCode>evaluateCode at 231 In verifyCode at 40 In fevalJSON at 14] [Warning: Function pause has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In verifyCode>evaluateCode at 231 In verifyCode at 40 In fevalJSON at 14] [Warning: Function simulink has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In verifyCode>evaluateCode at 231 In verifyCode at 40 In fevalJSON at 14] Elapsed time is 0.248036 seconds.

3   Pass
%% cases=50; nKnots=zeros(cases,1); KnotTime=zeros(cases,1); load Knots_contest.mat for n=1:cases a=testsuite(n).a; xyIn=testsuite(n).xyIn; wts=testsuite(n).wts; rng(2,'twister') time0 = cputime; xyOut=solver(a,xyIn,wts); KnotTime(n) = cputime - time0; if size(unique(xyOut,'rows'),1)<length(wts) nKnots(n)=Inf; % Points must be unique else nKnots(n)=numKnots(xyOut,a); end end for n=1:cases fprintf('%2i KnotTime(msec) %5i Knots %4i\n',n,floor(KnotTime(n)*1000),nKnots(n)) end TKnotTime=sum(KnotTime); fprintf('Sum KnotTime %5i msec\n',floor(TKnotTime*1000)) Tknots=sum(nKnots);; fprintf('Knot Score %10.2f\n',Tknots) fprintf('Cody Maximum allowed Elapsed time is approximately 53 seconds\n') toc feval( @assignin,'caller','score',min( 2000,Tknots ) );

1 KnotTime(msec) 779 Knots 13 2 KnotTime(msec) 699 Knots 53 3 KnotTime(msec) 39 Knots 6 4 KnotTime(msec) 39 Knots 30 5 KnotTime(msec) 70 Knots 13 6 KnotTime(msec) 299 Knots 32 7 KnotTime(msec) 69 Knots 7 8 KnotTime(msec) 1230 Knots 20 9 KnotTime(msec) 49 Knots 9 10 KnotTime(msec) 59 Knots 33 11 KnotTime(msec) 50 Knots 3 12 KnotTime(msec) 39 Knots 3 13 KnotTime(msec) 1579 Knots 25 14 KnotTime(msec) 70 Knots 0 15 KnotTime(msec) 219 Knots 46 16 KnotTime(msec) 1310 Knots 53 17 KnotTime(msec) 380 Knots 14 18 KnotTime(msec) 70 Knots 25 19 KnotTime(msec) 419 Knots 42 20 KnotTime(msec) 480 Knots 53 21 KnotTime(msec) 89 Knots 23 22 KnotTime(msec) 299 Knots 35 23 KnotTime(msec) 1210 Knots 37 24 KnotTime(msec) 259 Knots 9 25 KnotTime(msec) 39 Knots 3 26 KnotTime(msec) 39 Knots 5 27 KnotTime(msec) 250 Knots 0 28 KnotTime(msec) 119 Knots 9 29 KnotTime(msec) 69 Knots 1 30 KnotTime(msec) 600 Knots 31 31 KnotTime(msec) 230 Knots 25 32 KnotTime(msec) 1220 Knots 20 33 KnotTime(msec) 109 Knots 0 34 KnotTime(msec) 90 Knots 37 35 KnotTime(msec) 179 Knots 17 36 KnotTime(msec) 29 Knots 14 37 KnotTime(msec) 29 Knots 3 38 KnotTime(msec) 700 Knots 57 39 KnotTime(msec) 539 Knots 21 40 KnotTime(msec) 190 Knots 12 41 KnotTime(msec) 810 Knots 34 42 KnotTime(msec) 620 Knots 34 43 KnotTime(msec) 39 Knots 7 44 KnotTime(msec) 250 Knots 36 45 KnotTime(msec) 120 Knots 10 46 KnotTime(msec) 29 Knots 1 47 KnotTime(msec) 619 Knots 54 48 KnotTime(msec) 119 Knots 29 49 KnotTime(msec) 1420 Knots 51 50 KnotTime(msec) 180 Knots 21 Sum KnotTime 18470 msec Knot Score 1116.00 Cody Maximum allowed Elapsed time is approximately 53 seconds Elapsed time is 21.227281 seconds.