Example #1
0
 static void IsolateSet(int set, Region region, SudokuModel model)
 {
     var cells = model.GetCells(region.Type, region.I);
     var cellsNotContainedBySet = cells.Where(cell => (model.GetPossibilitySetCell(cell.Column, cell.Row) | set) != set).ToList();
     var numCellsContainedBySet = cells.Length - cellsNotContainedBySet.Count;
     if (numCellsContainedBySet != set.HiBitCount()) {
         return;
     }
     // we now know that each of the numbers in the set must be exclusively in
     // one of the contained cells, so we eliminate that set from all other cells'
     // possibility bits.
     var mask = ~set;
     foreach (var cell in cellsNotContainedBySet) {
         var poss = model.GetPossibilitySetCell(cell.Column, cell.Row);
         model.SetPossibilitySetCell(cell.Column, cell.Row, poss & mask);
     }
 }