DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

1. Registered User
Join Date
Dec 2005
Posts
4

## ...

...
Last edited by Akole; 02-13-2006 at 06:38 PM.

2. Registered User
Join Date
Dec 2005
Location
New Jersey
Posts
290
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++) {
}
}

/** this will be called only for the squares that are given to us */
public Square(int num) {
if (num => 1 && num <= 9) {
}
}

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!

3. Registered User
Join Date
Mar 2005
Location
UK, London
Posts
150
ArrayList<Integer> possibilities = new ArrayList<Integer>();
Implemented as of java 1.5, from what i have read (I think)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise