I am trying to make a Sudoku-solver, so far I have made the class 'board' and a way to enter which field you want to fill with a number (the beginning numbers). How should I store the numbers? With arrays?
This is a discussion on advice for Sudoku-solver within the C++ Programming forums, part of the General Programming Boards category; I am trying to make a Sudoku-solver, so far I have made the class 'board' and a way to enter ...
I am trying to make a Sudoku-solver, so far I have made the class 'board' and a way to enter which field you want to fill with a number (the beginning numbers). How should I store the numbers? With arrays?
Operating Systems:
- Ubuntu 9.04
- XP
Compiler: gcc
Use [3][3][3] array for storing numbers, In order to solve it think for yourself, do you know the rules?
lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu
yes, with counting the total value of the numbers in rows, columns and squares.
Edit: [3][3][3] is wrong, because you have 27 fields in that array and you need: 9 * 9 fields. [9][9] seems to be the right solution for me.
Last edited by Ideswa; 07-31-2006 at 05:58 AM.
Operating Systems:
- Ubuntu 9.04
- XP
Compiler: gcc
I wrote a (lousy) logical solver recently. I used a Cell class, and a Sudoku (board) class which had 3 copies of a [81] array of Cells: one sorted by rows, one by column and one by regions. Each cell object also had 2 pointers (or array indices) to the corresponding Cells in the other 2 arrays, so that by modifying a cell in respect to a row, I could modify the corresponding cells in column and region. Having three copies of the board may not be too efficient, but it sure made scanning each row, column and region a lot easier (and the program works reasonably fast).
On second thought it would have been even better to use one [3][81] array for the three copies of the board (I basically had a lot of copied-n-pasted code), but I was almost finished when it occurred to me.
Do it the VERY long way! the one that would have ~9^40 possibilities!!!
I've been thinking about making one for ages, but I haven't gotten around to it. I'll prob do it next year in college when I should be doing something different.
However, I'd recommend that you attempt to make the solver function the same way you attempt to solve the puzzle yourself. If you can solve a puzzle, do one again, but write down the methodology you employ to solve it, and the pseudocode a rough function. There should be a number of functions you could use in your program. As I said, try some puzzles, write down how you solve them, and then try to write the program.
EDIT - maybe he meant a [9][9][9] array ...
Here's an article about it: http://www.osix.net/modules/article/?id=792.
Thanks for the tips!
Operating Systems:
- Ubuntu 9.04
- XP
Compiler: gcc