Sudoku Programmers Forum Index

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in          Games  Calendar

Log in to check your private messagesLog in to check your private messages   

Hashset and array

 
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Programming sudoku
View previous topic :: View next topic  
Author Message
andyp1983

Joined: 26 Feb 2010
Posts: 2
:

Items
PostPosted: Mon Mar 29, 2010 7:18 pm    Post subject: Hashset and array Reply with quote

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]);
}

}
}

}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Programming sudoku All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Sudoku Programmers topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group

Igloo Theme Version 1.0 :: Created By: Andrew Charron