Sudoku

• 01-28-2006, 02:45 PM
Akole
...
...
• 01-28-2006, 03:25 PM
destin
If you want to return the answer of a specified square, then you're going to need to solve it first. I would recommend having a class Square, which would hold all the possible values of that square.
The board would be a 9 by 9 array of these squares.
Code:

```class Square {     ArrayList<Integer> possibilities = new ArrayList<Integer>();         public Square() {         for (int i = 1; i <= 9; i++) {             possibilities.add(i);         }     }         /** this will be called only for the squares that are given to us */     public Square(int num) {         if (num => 1 && num <= 9) {             possibilities.add(num);         }     }         public void removePossibility(int num) {         possibilities.remove(num);     } }```
etc.

About the algorithm, you're going to have to come up with that yourself. For example, if you have a number 4 given to you at index (1, 0), then you'll have to do something like:
Code:

```for (int i = 0; i < 9; i++) {     if (i != 0) {         square[1][i].remove(4);     }     if (i != 1) {         square[i][0].remove(4);     } } for (int i = 0; i < 3; i++) {     for (int j = 0; j < 3; j++) {         if (i != 1 and j != 0) {             square[i][j].remove(4);         }     } }```
Good luck! :)
• 01-30-2006, 09:42 AM
major
Quote:

ArrayList<Integer> possibilities = new ArrayList<Integer>();
Implemented as of java 1.5, from what i have read (I think) :confused: