Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If this is what you need (numbers increase columnwise but rows need to be filled first):</p> <pre><code>for 16: 0 6 11 1 7 12 2 8 13 3 9 14 4 10 15 5 for 17: 0 6 12 1 7 13 2 8 14 3 9 15 4 10 16 5 11 </code></pre> <p>You need to define which column is getting the remainders:</p> <pre><code>int remainder = total % 3; </code></pre> <p>if remainder is 1, only first column is 6 elements. if remainder is 2, first &amp; second columns are 6 elements. You need to calculate startIndex and endIndex according to this.</p> <p>So;</p> <pre><code>int pageSize = total / 3; int remainder = total % 3; int startIndex = column * pageSize + min(column, remainder); int endIndex = startIndex + pageSize + (remainder &gt; column ? 1 : 0); </code></pre> <p>should work. I just tested it, it works for different rowsizes than 3.</p> <p>Here is how I got the formulas, drawing tables is good practice for sorting out such algortihms:</p> <p>r:Remainder, c:column, ps:pagesize (as calculated above)</p> <pre><code>StartingIndex: . |r:0 |r:1 |r:2 ---------------------- c:0|0 |0 |0 ---------------------- c:1|ps |ps+1 |ps+1 ---------------------- c:2|ps*2|ps*2+1|ps*2+2 </code></pre> <p>You can see a pattern if you extend the table for rowsize 4:</p> <pre><code>StartingIndex: . |r:0 |r:1 |r:2 |r:3 ------------------------------ c:0|0 |0 |0 |0 ------------------------------ c:1|ps |ps+1 |ps+1 |ps+1 ------------------------------ c:2|ps*2|ps*2+1|ps*2+2|ps*2+2 ------------------------------ c:3|ps*3|ps*3+1|ps*3+2|ps*3+3 </code></pre> <p>the value you are adding is the minimum of the related column and remainder</p> <p>Similarly for the endIndex, desired columns length can be seen when you build a table for given remainder vs column. I won't write that for now because it is taking too much time to draw the tables here and I believe you already got the idea.</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