| andyp1983
| Joined: 26 Feb 2010 | Posts: 2 | : | | Items |
|
Posted: Mon Mar 29, 2010 7:18 pm Post subject: Hashset and array |
|
|
ive worked out how to find the possible numbers in my board but now im trying to place the sole candidates in the grid. the problem im havin is placing the numbers in the grid, it seems to place the first number in the grid in the right spot, but doesnt place the rest of them, can anyone help?
all = new HashSet<Integer>();
for (int i= 0; i< 9; i++)
all. add(new Integer(i+1));
if (grid[r][c] != 0) return;
Set<Integer> used = new HashSet<Integer>();
for (int rNdx = 0; rNdx < 9; rNdx++)
if (grid[rNdx][c] != 0) used. add(grid[rNdx][c]);
for (int cNdx = 0; cNdx < 9; cNdx++)
if (grid[r][cNdx] != 0)
used. add(grid[r][cNdx]);
int minR = (r/3) * 3;
int minC = (c/3) * 3;
for (int rNdx = minR; rNdx < minR + 3; rNdx++)
for (int cNdx = minC; cNdx < minC + 3; cNdx++)
if (grid[rNdx][cNdx] != 0)
used. add(grid[rNdx][cNdx]);
Set<Integer> moves = new HashSet<Integer>(all);
moves. removeAll(used);
//System.out.println("r: " + r + "; c: " + c +"; v: " + moves);
Iterator it=moves. iterator();
if(moves.size() < 2)
{
for(int i= 0; i < 9; i++)
{
for(int j = 0; j < 9; j++)
{
if(it. hasNext())
grid[r][c] = grid[i][j];//
System.out.print(grid[i][j]);
}
}
}
} |
|