I am trying to write a function that takes the following 2 parameters:
- A sentence as a string
- A number of lines as an integer
So if I was to call formatLines("My name is Gary", 2); ...
The possible outcomes would be:
- array("My name is", "Gary");
- array("My name", "is Gary");
- array("My", "name is Gary");
It would return: array("My name", "is Gary"); because the difference in character counts for each line is as small as possible.
So the part I am ultimately stuck on is creating an array of possible outcomes where the words are in the correct order, split over x lines. Once I have an array of possible outcomes I would be fine working out the best result.
So how would I go about generating all the possible combinations?
Regards
Joe