Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Edit: final answer for real ultimate power!</p> <p>So for gridbox, you are basically taking i and j and interleaving their digits in base(square). E.g., given i and j in base(scale), you are computing:</p> <p>i(2)j(2)i(1)j(1)</p> <p>Where (n) signifies the digit base(scale).</p> <p>So that's easy enough to speed up: just keep a running tally of each digit's contribution to the final value of gridbox(...).</p> <p>Speeding up gridbox1(...) is even easier. Basically, you are computing:</p> <pre><code>Square * Square *(j\Square * Square + (j Mod Square)) </code></pre> <p>Now, <code>(j Mod Square)</code> expands to <code>(j - j\Square*Square)</code> which reduces the above to:</p> <pre><code>Square * Square *(j\Square * Square + (j - j\Square*Square)) </code></pre> <p>Which simplifies to:</p> <pre><code>Square * Square *(j\Square * Square + j - j\Square*Square) </code></pre> <p>Which simplifies to:</p> <pre><code>Square * Square * (j) </code></pre> <p>Here's the final loop:</p> <pre><code>Dim Square2 = Square * Square Dim Square3 = Square2 * Square Dim Square4 = Square2 * Square2 Dim j2_offset = 0 Dim j2_interleaved_offset = 0 Dim j2_value_offset= 0 For j2 = 0 To Square - 1 Dim j1_offset = 0 Dim j1_interleaved_offset = 0 For j1 = 0 To Square - 1 Dim i2_offset = 0 Dim i1_interleaved_offset = 0 For i2 = 0 To Square - 1 For i1 = 0 To Square - 1 Dim box = j2_offset + j1_offset + i2_offset + i1 gridbox(box) = j2_interleaved_offset + i2_interleaved_offset + j1_interleaved_offset + i1 gridbox1(gridbox(box)) = j2_offset + j1_offset Next i2_offset += Square i2_interleaved_offset += Square2 Next j1_offset += Square2 j1_interleaved_offset += Square Next j2_offset += Square3 j2_interleaved_offset += Square3 Next </code></pre>
    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