Hi all,
I was wondering if there is an algorithm to split a line into multiple lines, so that the resulting set of multiple lines fit into a squared shape rather than a wide rectangular shape. Let me give some examples,
Input: Hi this is a really long line.
Output:
Hi this is
a really
long line
Input: a b c d e f
Output:
a b c
d e f
Input: This is really such looooooooooooooooooooong line.This is the end.
Output:
This is really such
looooooooooooooooooooong
line This is the end.
If you see in the above examples, input line fits into a wide rectangle. But the output more or less fits into a squared shape.
Essentially what needs to be done here is simply count the number of characters in the line, take the square root of that number. Then put square root number of characters in each line. But in the above example, the splitting needs to be done by respecting word wraps instead of characters. Is there any standard algorithm for this? Any code examples/ pointers would be appreciated!