View previous topic :: View next topic |
Author |
Message |
| ChPicard
| Joined: 12 Mar 2008 | Posts: 82 | : | Location: Montreal, Canada | Items |
|
Posted: Wed Aug 12, 2009 8:31 pm Post subject: row R and column C numbers |
|
|
Hi
How to calculate the row R and column C numbers knowing the position X of the givens (X>=0 and X<81) ?
Thank you |
|
Back to top |
|
|
| Pete
| Joined: 09 Jun 2008 | Posts: 18 | : | Location: Somerset, NJ | Items |
|
Posted: Wed Aug 12, 2009 8:47 pm Post subject: |
|
|
Assuming a 9x9 grid, I would think that
* R would be X / 9
* C would be X % 9
where % is the modulo operator.
That would give a number from 0 to 8 for each. Of course, you could add 1 to each if you want the range to be 1 to 9.
Is that what you're looking for? |
|
Back to top |
|
|
| leeo
| Joined: 24 Jun 2009 | Posts: 6 | : | Location: USA NW | Items |
|
Posted: Tue Aug 25, 2009 12:46 pm Post subject: |
|
|
Sudoku grids are small enough that defining arrays may be faster than working with calculating the position. One array I have lists each of the 20 cells touching each of the 81 cells in the grid. This array has 1620 elements, but the calculation need only be done once, on building the array. Further, an inefficient "brute force" search can be employed to build the arrays, and the employment of the array will still be efficient. |
|
Back to top |
|
|
|