Comments (500 Characters Max)
M-Code function indexList = binpack(songList, mediaLength) % Arrange elements of the song list so that total play time % is as close as possible to the target time. In general, % not every song will be used. % This is an example entry. It has already been submitted % to the contest as BINPACK EXAMPLE. To submit your % entry, replace this function with your own. full = 0; N = 0; while ~full % Compute length of first N songs. Vectorize schmectorize.. length_used = 0; for k = 1:N length_used = length_used + songList(k); end % Compute blank space blank_space = mediaLength - length_used; % Did the last song fit? If yes, try another. if blank_space > 0 N = N + 1; else full = 1; end end % We were able to fit N-1 songs onto the tape.. indexList = [1:N-1];