/// <summary> /// Solves a sudoku board. /// </summary> /// <param name="board">The board to solve.</param> /// <param name="index">The zero-based index up to 99.</param> /// <returns>True if the board was solved.</returns> private static bool Solve(SudokuBoard board, int index) { if (index == 9 * 9) { return(true); } SudokuSquare square = board.Squares[index / 9]; int inSquareIndex = index % 9; for (int i = 1; i <= 9; i++) { square.Values[inSquareIndex] = i; if (board.IsValid(index)) { bool solved = SudokuSolver.Solve(board, index + 1); if (solved) { return(true); } } } square.Values[inSquareIndex] = 0; return(false); }
static void Main(string[] args) { //List<List<char>> paths = GraphSearch.AllPaths(Graph.MakeSampleGraph()); SudokuSolver.SudokuBoard board = new SudokuSolver.SudokuBoard(); SudokuSolver.Solve(board); Console.WriteLine(board); }
public static void Solve(SudokuBoard board) { SudokuSolver.Solve(board, 0); }