public Puzzle findBadMinimalPuzzle() { Puzzle workPuzzle = new Puzzle(); for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { workPuzzle.values[i, j] = this.values[i, j]; } } for (int y = 0; y < 9; y++) { for (int x = 0; x < 9; x++) { //Check every location on the puzzle we're looking at to see if we can reduce it without making it non-unique int oldValue = workPuzzle.values[x, y]; if (oldValue != 0) { workPuzzle.values[x, y] = 0; if (!workPuzzle.isSolutionUnique()) { workPuzzle.values[x, y] = oldValue; } } } //Console.WriteLine("row {0}", y); } return(workPuzzle); }
//Returns a puzzle that: //a) has a unique solution //b) matches this puzzle except with one number removed //if such a puzzle exists. If no such puzzle exists, return null. public Puzzle findReducedPuzzle(int x, int y) { Puzzle reducedPuzzle = new Puzzle(); for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { reducedPuzzle.values[j, i] = this.values[j, i]; } } if (this.values[x, y] != 0) { reducedPuzzle.values[x, y] = 0; if (reducedPuzzle.isSolutionUnique()) { return(reducedPuzzle); } } return(null); }