public static List <int> FindSingularizedCells(SudokuPuzzle puzzle1, SudokuPuzzle puzzle2, int cellIndex) { //Debug.Assert(puzzle1.Length == puzzle2.Length); var result = new List <int>(); foreach (int i in puzzle1.Peers(cellIndex)) { if (puzzle1.Cells[i].Length > 1 && puzzle2.Cells[i].Length == 1) { result.Add(i); } } return(result); }
public virtual SudokuPuzzle ApplyConstraints(int cellIndex, int value) { SudokuPuzzle puzzle = (SudokuPuzzle)this.Clone(); //Standard Sudoku constraint logic: Set this cell to one and only one candidate, and remove this value from the candidate list of all its peers puzzle.Cells[cellIndex] = new int[] { value }; foreach (int peerIndex in puzzle.Peers(cellIndex)) { var newPeers = puzzle.Cells[peerIndex].Except(new int[] { value }).ToArray(); if (!newPeers.Any()) { return(null); } puzzle.Cells[peerIndex] = newPeers; } return(puzzle); }