Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to simplify this Sodoku Code?
    text
    copied!<p>SquareExp2 can be 9 or 16</p> <p>Square can be 3 or 4</p> <p>The Length of the gridbox and gridbox1 array can be 0 to 80 or 0 to 255</p> <p>(you see the pattern now)</p> <p>This code is ran only one time, at the start of the program.</p> <pre><code> For j = 0 To squareExp2 - 1 For i = 0 To squareExp2 - 1 box = (j * squareExp2) + i gridbox(box) = ((j \ Square) * squareExp2 * Square) + ((j Mod Square) * Square) + (i \ Square) * squareExp2 + (i Mod Square) gridbox1(gridbox(box)) = ((j \ Square) * squareExp2 * Square) + (((j Mod Square) * Square) * Square) Next Next </code></pre> <p>The goal of the code above is to move the code from</p> <pre><code> k = (gridRow(pos) \ iSquare) * iSquare l = (gridCol(pos) \ iSquare) * iSquare For i = l To l + iSquare - 1 For j = k To k + iSquare - 1 box = (j * squareExp2) + i foundNumber(grid(box)) = grid(box) Next Next </code></pre> <p>to</p> <pre><code> j = myGridbox1(i) For x = j To j + squareExp2 - 1 foundNumber(grid(myGridbox(x))) = grid(myGridbox(x)) Next </code></pre> <p><strong>* edit *</strong></p> <p>in the end</p> <pre><code> Dim Square2 As Integer = iSquare * iSquare Dim Square3 As Integer = Square2 * iSquare Dim Square4 As Integer = Square2 * Square2 Dim j2_offset As Integer = 0 For j2 As Integer = 0 To iSquare - 1 Dim j1_offset As Integer = 0 Dim j1_interleaved_offset As Integer = 0 For j1 As Integer = 0 To iSquare - 1 Dim i2_offset As Integer = 0 Dim i2_interleaved_offset As Integer = 0 Dim j_offset_value As Integer = j2_offset + j1_offset For i2 As Integer = 0 To iSquare - 1 Dim offset_value As Integer = j_offset_value + i2_offset Dim interleaved_value As Integer = j2_offset + i2_interleaved_offset + j1_interleaved_offset For i1 As Integer = 0 To iSquare - 1 box = offset_value + i1 gridbox(box) = interleaved_value + i1 gridbox1(gridbox(box)) = j_offset_value Next i2_offset += iSquare i2_interleaved_offset += Square2 Next j1_offset += Square2 j1_interleaved_offset += iSquare Next j2_offset += Square3 Next </code></pre> <p><strong>Update</strong> little followup, a few months later.</p> <p>It was for a sudoku program and you can find where it being used <a href="http://www.codeproject.com/KB/vb/CodeBehindSudoku.aspx" rel="nofollow noreferrer">here</a></p>
 

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