Note that there are some explanatory texts on larger screens.

plurals
  1. POSudoku - Region testing
    primarykey
    data
    text
    <p>I'm creating a sudoku generator, using a 'brute-force' randomity approach. I have been able to check the x / y axis for duplicate numbers just fine using the code:</p> <pre><code>for(l=0; l&lt;9; l++){//Makes all vertical work. if(sudoku[l][j] == temp){ isUsed=true; } } for(m=0; m&lt;9; m++){//makes all horizontal work if(sudoku[i][m] == temp){ isUsed=true; } } </code></pre> <p>I decided to implement the 'box' or 'region' checking (where you check every 3x3 square from the origin) and I just can't seem to wrap my head around the code. Here's what I've done so far. I just can't quite figure out where my logic error lies (for the record the program will run with this code, but will not check regions properly)</p> <pre><code>rowbase = i-(i%3); if(i==2 || i==5 || i==8 ){ if(rowbase == 0 || rowbase == 3 || rowbase == 6){ isUsed= RegionCheck.RegCheck(rowbase, sudoku); } } </code></pre> <p>Contents of regionCheck.java:</p> <pre><code> boolean okay = false; int[] regionUsed = new int[9]; int i=0, j=0, regionTester=0, counter=0, numcount; for (i=regionTester; i&lt;regionTester+3; i++){ for (; j&lt;3; j++){ regionUsed[counter]=sudoku[i][j]; counter++; } } for(i=0; i&lt;9; i++){ numcount=regionUsed[i]; for(j=0; j&lt;9; j++){ if(j==i){ //null } else if(numcount == regionUsed[j]){ okay=false; } } } return okay; </code></pre> <p>Somewhere along the way I'm just getting lost and not understanding how to 'select' a region and iterate through regions. </p> <p>Full source here: <a href="http://ideone.com/FYLwm" rel="nofollow">http://ideone.com/FYLwm</a></p> <p>Any help on simply how to 'select' a region for testing and then iterate through it would be greatly appreciated as I'm really out of ideas.</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.
 

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