I am a software developer with a rather simple problem. I don't really know how to express it in mathematical terms - I'll just try to write it down:


I have multiple different files... let's say 20 files. Each file can have a very different size. Some are very big, some are rather small. Each file is smaller than 3MB though.


My task is to form batches of files that are all as close to 3MB in size, but not more. This has to do with certain transmission limits.


The end result must be the minimal amount of file-batches possible.


How would I go about this? My pragmatic approach would be to just sort descending by file size and then start stacking a batch until 3MB would be exceeded, then start the next batch.


But is this really the mathematically best approach?



Make multiple batches of maximum size, different sized objects
Your problem is called [bin packing](https://en.wikipedia.org/wiki/Bin_packing_problem), and there is a vast literature on exact and approximation algorithms (see the bibliography on the Wikipedia page).


