-2

Sudoku ex1

While solving sudoku I can remove possibility digits (1) and (2) from the cells D[1,2] and D[2,2]. Because (8) and (9) are possible only in those cells, so those cells are either (8 and 9) or (9 and 8). This means that digits (1) and (2) are at the 3rd line of the D block. Thats why I can eliminate the possibility of the digit (1) from the cell A[3,3].

I have been configuring a function to do this during last 40 hours, but couldn't manage. Is there anyone who can make the function to detect this type of intellectual issue (eliminating some possibilities because some other n count of possibilities can exist only in n count of cells, in our case 2 digits 8 and 9 can exist in 2 cells D[1,2] and D[2,2]).

Please dont advice me about other functions of sudoku; I have already done them, the only algorithm that I couldn't program is this one. Btw you can use r[i] (string which consists the possibilities for the row number i), c[i] for the column, and b[i] for the blocks (ex: b[4] (in this image block A) = 1,2,3,4,5,6,7 because 8 and 9 are already defined). Thanks

TLama
  • 75,147
  • 17
  • 214
  • 392
Hasan A.
  • 23
  • 4
  • I couldnt even think how to do this. If you can hint the way how to make the function I can make that – Hasan A. Oct 19 '12 at 19:38
  • Please redo the question. After reading it 3 times, I still don't understand what exactly you are trying to do and why is that so difficult. – trailmax Oct 19 '12 at 19:40
  • the digits in the brackets are the possible numbers that can suit those cells. In the block D, you can see that 8 and 9 can suit only in 2 cells, so they are definetly there. This means I can remove 1 and 2 from those cells. – Hasan A. Oct 19 '12 at 19:42
  • After removing those possibilities (1 and 2) from those cells, 1 and 2 are only possible in two cells D[3,1] and D[3,3]. This means they are definetly there which lets us to remove (1) from A[3,3]. Because (1) will be either in D[1,3] or in D[3,3]. A digit in sudoku can't be repeated in a row, column or block. – Hasan A. Oct 19 '12 at 19:52
  • What I have already done, is dynamically creating 81 cells (array of TEdits), entering the given values to some cells and pressing the button solve - algorithms check all the possible numbers for empty cells, then check the (rows, columns and 3x3 blocks) and eliminates unnecessary possibilities. This process is recursive and can solve very easy sudokus. But if I can write the function above, my program can solve the most difficult sudokus. I need your help guys – Hasan A. Oct 19 '12 at 20:07

1 Answers1

1

I really don't see the problem, you basically already answered your problem. In general you should do the following:

Step 1: Loop over all 9 cells of one block and check if (1) is contained only in two cells.

Step 2: If not, try the next number. If yes, Loop over all 9 cells and check if (2) is also in those two cells but not in any other of the remaining 7.

Step 3: If not, check the next number. If yes, remove the other possibilities of the two cells except for the two numbers you found and you are basically done.

Step 4: If no matching number could be found for (1) (or any larger number that was chosen in the "not" part of step 2), start over from step 1 but trying the next number, unless you are already at 8, then you can stop.

In the end you could dynamically extend the same pattern for 3 numbers in 3 cells, 4 numbers...

philkark
  • 2,417
  • 7
  • 38
  • 59
  • No problem, only to point it out. You can of course use the same algorithm not only for cells but also for any row or column. – philkark Oct 22 '12 at 15:20