Cody

# Problem 1136. Knots Contest: Score (ContestSuite)

Solution 181429

Submitted on 25 Dec 2012 by @bmtran
• Size: 956
• 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
%% 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 rehash path % Make numKnots.m available toc

``` ans = /users/msssystem3/Knots_contest.mat ans = /users/msssystem3/numKnots.m [Warning: Function /opt/mlsedu/mdcsserver/latest/m/web_common/shadow/license.m has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Function /opt/mlsedu/mdcsserver/latest/m/common/shadow/home.m has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Function /opt/mlsedu/mdcsserver/latest/m/common/shadow/keyboard.m has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Function /opt/mlsedu/mdcsserver/latest/m/common/shadow/more.m has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] [Warning: Function /opt/mlsedu/mdcsserver/latest/m/common/shadow/pause.m has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.] [> In verifyCode>evaluateCode at 226 In verifyCode at 40 In fevalJSON at 14] Elapsed time is 3.671627 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)) T_score=6.5*exp(TKnotTime/23); Tknots=sum(nKnots);; fprintf('Time Score %10.2f\n',T_score) fprintf('Knot Score %10.2f\n',Tknots) fprintf('Total Score %10.2f\n',Tknots+T_score) fprintf('Cody Maximum allowed Elapsed time is approximately 53 seconds\n') toc feval( @assignin,'caller','score',min( 2000,Tknots+floor(T_score) ) );

``` 1 KnotTime(msec) 1279 Knots 7 2 KnotTime(msec) 1509 Knots 43 3 KnotTime(msec) 109 Knots 5 4 KnotTime(msec) 100 Knots 23 5 KnotTime(msec) 160 Knots 10 6 KnotTime(msec) 549 Knots 28 7 KnotTime(msec) 120 Knots 6 8 KnotTime(msec) 1490 Knots 17 9 KnotTime(msec) 159 Knots 9 10 KnotTime(msec) 160 Knots 26 11 KnotTime(msec) 89 Knots 3 12 KnotTime(msec) 90 Knots 1 13 KnotTime(msec) 1689 Knots 19 14 KnotTime(msec) 140 Knots 0 15 KnotTime(msec) 389 Knots 38 16 KnotTime(msec) 2080 Knots 41 17 KnotTime(msec) 549 Knots 22 18 KnotTime(msec) 149 Knots 17 19 KnotTime(msec) 860 Knots 32 20 KnotTime(msec) 879 Knots 56 21 KnotTime(msec) 149 Knots 19 22 KnotTime(msec) 620 Knots 27 23 KnotTime(msec) 1530 Knots 37 24 KnotTime(msec) 370 Knots 8 25 KnotTime(msec) 79 Knots 0 26 KnotTime(msec) 69 Knots 2 27 KnotTime(msec) 250 Knots 0 28 KnotTime(msec) 129 Knots 7 29 KnotTime(msec) 69 Knots 2 30 KnotTime(msec) 829 Knots 18 31 KnotTime(msec) 340 Knots 20 32 KnotTime(msec) 1490 Knots 19 33 KnotTime(msec) 180 Knots 0 34 KnotTime(msec) 209 Knots 25 35 KnotTime(msec) 260 Knots 10 36 KnotTime(msec) 110 Knots 9 37 KnotTime(msec) 49 Knots 2 38 KnotTime(msec) 1389 Knots 55 39 KnotTime(msec) 740 Knots 16 40 KnotTime(msec) 290 Knots 11 41 KnotTime(msec) 1149 Knots 34 42 KnotTime(msec) 1120 Knots 35 43 KnotTime(msec) 90 Knots 6 44 KnotTime(msec) 360 Knots 12 45 KnotTime(msec) 189 Knots 9 46 KnotTime(msec) 39 Knots 0 47 KnotTime(msec) 1220 Knots 51 48 KnotTime(msec) 190 Knots 26 49 KnotTime(msec) 2039 Knots 50 50 KnotTime(msec) 289 Knots 21 Sum KnotTime 28409 msec Time Score 22.35 Knot Score 934.00 Total Score 956.35 Cody Maximum allowed Elapsed time is approximately 53 seconds Elapsed time is 34.456946 seconds. ```