Skip to content
Create a gist now

Instantly share code, notes, and snippets.

anonymous / secret

public boolean search(Sudoku puzzle) {
if(puzzle.checkContradiction()) return false;
if(puzzle.checkSolved()) return true;
//for cell with fewest candidates, loop over candidates
Cell c = puzzle.getEasiest();
while(c.numCandidates() > 0) {
int candidate = c.getCandidates()[0];
Sudoku s = (Sudoku) puzzle.clone();
s.set(c.getRowNum(), c.getColNum(), candidate);
if(search(s)) {
puzzle = s;
return true;
else c.remove(candidate);
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.