![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2006
Posts: 9
Rep Power: 0
![]() |
sudoku help needed
i coded a sudoku program ,but i am having a problem with it. my sudoku can find whether row/col/and 3*3 duplicate numbers(uses isLegal() function). grid is generated by random numbers .these random numbers will go into empty grids in the square. if duplicate numbers exists(isLegal function becomes false) i make the current square empty. after that i want to count other numbers and check whether its valid or not, if valid it will go to the empty squares.any help is appreciated..
code------------------------------------------------------------------- bool generation(int newGrid[9][9],int r,int c) //generation function with arg { if(c == 9) { if(++r == 9) return true; c = 0; } if(newGrid[r][c] != 0) return generation(newGrid, r, c + 1); do { const int randV = (rand() % 9) + 1; newGrid[r][c] = randV; if(!isLegal()) { newGrid[r][c] = 0; return false; } } while(!generation(newGrid, r, c + 1)); return true; } |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
You might wish to read the "How to post a question" thread at the top of the forum.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|