The following question was posted by @ruhroe about an hour ago. I was about to post an answer when it was filmed. This is unfortunate, as I thought it was quite interesting. I will return it in case the OP sees this, and also provide others with the opportunity to publish solutions.
The original question (which I edited):
The problem is to split the line into some spaces in the line based on criteria that partially depend on the number set by the user. If this number were, say, 5, each substring would contain:
- one word with 5 or more characters or
- as many consecutive words (separated by spaces) as possible, if the resulting line has no more than 5 characters.
For example, if the line was:
"abcdefg fg hijkl mno pqrs tuv wx yz"
the result will be:
["abcdefg", "fg", "hijkl", "mno", "pqrs", "tuv", "wx yz"]
"abcdefg" , ."fg" , "fg" 5 , , "fg hijkl" 5 ."hijkl" , .
?