Sudoku editor and solver with heavily use of LINQ. I have implemented most of all alghorithms not required reccurency. Written in C# 4.0. Solution for VS2010.

sudoku1.png

Example of Pointing Pairs method:

 protected override List<SudokuSolution> Solve_PointingPairs(SudokuBoard a_board, 
     bool a_all)
 {
     var pairs = (from box in a_board.BoxesNumbers()
                  from num1 in box
                  where num1.State == SudokuNumberState.sudokucellstatePossible
                  from num2 in box
                  where (num1.Row == num2.Row) || (num1.Col == num2.Col)
                  where (num2.State == SudokuNumberState.sudokucellstatePossible) &&
                        (num1.Index < num2.Index) &&
                        (num1.Number == num2.Number) &&
                        (from n in box
                         where (n.Index != num1.Index) &&
                               (n.Index != num2.Index) &&
                               (n.Number == num1.Number)
                         select n).All(
                             n => n.State != SudokuNumberState.sudokucellstatePossible)
                  select new
                  {
                      removed = (num1.Row == num2.Row) ? 
                          (from num in num1.RowNumbers().Except(num1.BoxNumbers())
                           where (num.State == 
                                       SudokuNumberState.sudokucellstatePossible) &&
                                     (num.Number == num1.Number)
                           select num).ToArray()
                       :
                           (from num in num1.ColNumbers().Except(num1.BoxNumbers())
                           where (num.State == 
                                         SudokuNumberState.sudokucellstatePossible) &&
                                     (num.Number == num1.Number)
                           select num).ToArray(),

                      stayed = new[] { num1, num2 },
                      unit2 = num1.BoxCells(),
                      unit1 = (num1.Row == num2.Row) ? num1.RowCells() : num1.ColCells()
                  }).TakeAllOrOne(a_all, obj => obj.removed.Length > 0).ToArray();

     return new List<SudokuSolution>(
         from obj in pairs
         select new SudokuSolution(SudokuSolutionType.PointingPair, 
             obj.removed, obj.stayed, null, new[] { obj.unit1, obj.unit2 }));
 }



My Blog: http://anutom.blogspot.com/

Last edited Feb 3, 2012 at 5:27 PM by tomanu, version 13