PDA

View Full Version : Sudoku


MindTheGap
01-20-2008, 12:55 PM
Recently, I have been interested in doing Sudoku puzzles. (I'm good at the easy ones, but no so good at the hard ones. ;) ) So I really want to create a C++ program to check if my Sudoku puzzle is finished or not ( Finished means 1-9 in all rows, columns, and 3x3 boxes).

So, if I have a multi-dimensional array (in this case 9x9), whats the best way to go about checking if it is done or not?

Dunna
01-21-2008, 11:23 AM
Since you have to have 1-9 in all rows and columns, I would simple use 2 for loops to go through each character of each row. I would have then pass the current row into a sort function and then compare the sorted array with an array called:
SortedNumber[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
If they match, the row has been completed successfully. Then do the exact same thing for each column. If all rows and columns have 1-9 then you effectively know that the puzzle is solved.