This week's book giveaway is in the Java in General forum. We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line! See this thread for details.
Hi, I was wondering if anyone could see the problem with this piece of code. It is the last phase(guessing phase) of a sudoku solver I am trying to write. It is called only when the puzzle cannot be solved using logical methods.
Basically it is a depth first search algorithm. I loop over the 2-d array of cells (comboboxes) and for each one that isEnabled() (i.e. the value as of cell has not been foound using previous logical methods) I add it to an ArrayList rank.
Then I store the possible elements of each undecided cell in an ArrayList OPEN and associate a CLOSED ArrayList with each one also.
Starting with the first element in rank, I look at its Open list, put then number in the combobox and increment...... [ this should only happen if the number does not contradict the rules of sudoku( must not be same num in row, col, square) However, the same number is getting displayed in rows, cols etc ]
When it fills all empty cells, it checks to see if sudoku is valid, it not go back to last undecide cell and pick different number of open. if everything in open list is in closed list, then clear() closed list and decrement back to previous undecided cell and proceed...and so on...
Whats bugging me is that it is trying numbers that already appear in the same row, column or square although I thought I had the condition coded correctly.