aspose file tools*
The moose likes Beginning Java and the fly likes ArrayLists  ;o( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ArrayLists  ;o(" Watch "ArrayLists  ;o(" New topic
Author

ArrayLists ;o(

Prionsios Mac Giollacom�in
Greenhorn

Joined: Jan 16, 2006
Posts: 12
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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ArrayLists ;o(