Distribute strings into minimum amount of lines

19 Views Asked by At

I am a software developer and I have a set of strings that I want to distribute into a minimum amount of lines using programming code. Each line has a known maximum length and I know the length of each string.

So I suppose the math question I have is: I have a collection of numbers that I want to distribute into collections with a known maximum sum and use a minimum amount of those collections.

Lets assume I have a max line length of 50 and I have these string lengths: 14,50,28,22,22,25,20,15

A solution could be (in random order): 14,20,15 (sum = 49) 50 (sum = 50) 28,22 (sum = 50) 22,25 (sum = 47)

Is there a mathematical formula or technique that can solve this puzzle?

I tried to search for similar questions, but I guess I don't know what keywords to search on. Also as a non-mathematician, its hard to tag this question properly.

1

There are 1 best solutions below

1
On BEST ANSWER

This problem is called bin packing problem and it is NP-Hard.