Finish 1998-12-21 00:00:00 UTC

edit of G.Mayraz

by Matt Beal

Status: Passed
Results: 0.36% blank
CPU Time: 33.689
Score: 155.976
Submitted at: 1998-12-15 09:07:23 UTC
Scored at: 2000-03-16 16:51:51 UTC

Current Rank: 384th
Based on: high-end performance2 (diff)

Comments
Please login or create a profile.
Code
function indexList = binpack(songList, mediaLength)

mediaLength = mediaLength-0.00001;
total_songs = length(songList);
num_random_trials = 100; 
rand('seed',sum(100*clock));
[tmp1,order] = sort(rand(num_random_trials,total_songs),2);
gap = mediaLength*ones(num_random_trials,1);
selected=logical(zeros(num_random_trials,total_songs));
for s=1:total_songs
  addIndex=find(gap>=songList(order(:,s))');
  if ~isempty(addIndex)
    gap(addIndex)=gap(addIndex)'-songList(order(addIndex,s));
    selected(addIndex,s)=ones(length(addIndex),1);
  end;
end;
[tmp2,bestTrial]=min(gap);
indexList=order(bestTrial,selected(bestTrial,:));