Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Perhaps it helps if you look at the problem like this:</p> <p>For your example, you have a string like this:</p> <pre><code>AA BB C DDDD E FFF </code></pre> <p>The space positions are the places where you could start a new column. Everywhere else you mustn't to keep same letters in the same column. So you actually can mark the space position like this:</p> <pre><code>AA1BB2C3DDDD4E5FFF </code></pre> <p>Now you have 5 positions where you can either break the column or not, as it's a binary decision, use a string of 0's and 1's for this and brute force every possible combination:</p> <pre><code>12345 00000 -&gt; no break at all, column count = 1, max. lines = 13 ... 01010 -&gt; your example, column count = 3, max. lines = 5 ... 11111 -&gt; breaks everywhere, column count = 6, max. lines = 4 </code></pre> <p>This is a brute force attempt, but you can easily see that the 1's count affects the column count (column count = number of 1's + 1) and you want to minimize max. lines, this should be possible to somehow calculate without having to test each combination.</p> <p>EDIT2: Didn't recognize you want 3 columns, this makes it easier as you know you will have only 3 1's, but it's still brute force.</p> <p>EDIT: Another approach I'd favorize:</p> <p>Write the letter counts like this:</p> <pre><code>A B C D E F 2 2 1 4 1 3 </code></pre> <p>You can now join letters that are next to each other. Always chose the two letters with the lowest count sum:</p> <pre><code>2 2 1 4 1 3 - lowest = "2 1" 2 3 4 1 3 - lowest = "1 3" 2 3 4 4 - lowest = "2 3" 5 4 4 - stop now, as we have 3 columns now Result: AABBC, DDDD, EFFF </code></pre> <p>This perhaps won't lead to the optimal solution, but it's a nice and easy way to solve your problem, I think.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload