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 185605

Submitted on 4 Jan 2013 by Richard Zapor

Correct

53Size
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
Code Input and Output
1
Pass
 
%%
feval(@assignin,'caller','score',100);

                    
2
Pass
 
%%
a{1} = [4.3078    2.5481    1.4903    5.4302    3.4142    2.9736    3.3768 ...
        2.1612    3.3024    0.3269    2.6761    4.2530    2.6648    1.9644 ...
        3.3389    22.122    4.1015    3.2104    2.3945    4.7151];
a{2} = [1.2671    3.1377    4.0687    4.1459    3.6469    6.1881    8.2452 ...
        7.3962    9.7071   10.4798   11.4082   12.2282   12.6320   13.9705 ...
        13.8851   15.6195   17.0187   18.5778   18.4140   20.0473];
a{3} = [1.6283    6.0703    8.1323    2.6226    3.1230    3.0081    6.1405 ...
        1.1896    4.2769    5.0951    6.4869    3.9215    2.5858    4.7130 ...
        4.5529];
a{4} = [40:-1:1]+.1;
a{5} = [1.0979    3.5540    1.8627    0.0849    3.2110    3.6466    4.8065 ...
        3.2717    0.1336    2.5008    0.4508    3.0700    3.1658    0.8683 ...
        3.5533    3.7528    2.7802    4.2016    1.6372    9.6254    1.3264 ...
        0.3160    4.3212    3.0192    0.7744    2.3970    1.7416    2.4751 ...
        1.0470    1.9091];
a{6} = [1 1 2 3 5 8 13 21 34]+.1;
a{7} = [0.8651    3.3312    0.2507    0.5754    2.2929    2.3818    2.3783 ...
        0.0753    0.6546    0.3493    0.3734    1.4516    1.1766    4.3664 ...
        0.2728    20.279    2.1335    0.1186    0.1913    1.6647    0.5888 ...
        2.6724    1.4286    3.2471    1.3836    1.7160    2.5080    3.1875 ...
        2.8819    1.1423    0.7998    1.3800    1.6312    1.4238    2.5805 ...
        1.3372    2.3817    2.4049    0.0396    0.3134];
a{8} = [pi*ones(1,10) exp(1)*ones(1,10)];
a{9} = [1.6041    0.2573    1.0565    1.4151    0.8051    0.5287    0.2193 ...
        0.9219    2.1707    0.0592    1.0106    0.6145    0.5077    1.6924 ...
        0.5913    0.6436    0.3803    1.0091    0.0195    0.0482    20.000 ...
        0.3179    1.0950    1.8740    0.4282    0.8956    0.7310    0.5779 ...
        0.0403    0.6771    0.5689    0.2556    0.3775    0.2959    1.4751 ...
        0.2340    8.1184    0.3148    1.4435    0.3510    0.6232    0.7990 ...
        0.9409    0.9921    0.2120    0.2379    1.0078    0.7420    1.0823 ...
        0.1315];
a{10}= [1.6041    0.2573    1.0565    1.4151    0.8051    0.5287    0.2193 ...
        0.9219    2.1707    0.0592    1.0106    0.6145    0.5077    1.6924 ...
        0.5913    0.6436    0.3803    10.091    0.0195    0.0482    20.000 ...
        0.3179    1.0950    1.8740    44.999    0.8956    0.7310    0.5779 ...
        0.0403    0.6771    0.5689    0.2556    0.3775    0.2959    1.4751 ...
        0.2340    0.1184    0.3148    1.4435    0.3510    0.6232    0.7990 ...
        0.9409    0.9921    0.2120    0.2379    1.0078    0.7420    1.0823 ...
        0.1315];
a{11}= [40*ones(1,50) ones(1,20)]+0.05;
a{12}= 4.3 + sin(1:100);
mediaLength=45;
for j=1:20 % warm-up
for i=1:12
   songList=a{i};
   indexList = binpack(songList,mediaLength) ;
end
end
net_gap=0;
t0=clock;
for j=1:100
for i=1:12
   songList=a{i};
   indexList = binpack(songList,mediaLength) ;
   indexList=unique(indexList); % No dupes
   total(i)=sum(songList(indexList));
   if total(i)>45+1.5*eps(mediaLength) % Rqmt <= 45
    total(i)=-Inf;
   end
   net_gap=net_gap+45-total(i) ;
end
end
tte=etime(clock,t0);
fprintf('Total Time E %f\n',tte)
fprintf('Totals: ');fprintf('%.4f  ',total);fprintf('\n')
fprintf('Net Gap: %.2f\n',net_gap)
%format long
fprintf('Performance: %.4f\n',net_gap/(12*45))
fprintf('Score=150*net_gap/(12*45)+3*time: %.3f\n',150*net_gap/(12*45)+tte*3)
Score=150*net_gap/(12*45)+tte*3;
assert(Score<Inf)
feval( @assignin,'caller','score',floor(min( 100,Score )) );
Total Time E 0.584551
Totals: 44.9940  44.9514  44.9785  44.8000  44.9965  44.6000  44.9992  44.5840  44.9988  44.9990  44.2500  44.9950
Net Gap: 188.02
Performance: 0.3482
Score=150*net_gap/(12*45)+3*time: 53.981