static void Main(string[] args)
Console.WriteLine("Welcome to the sudoku-solver!");
int[,] sudoku = {{5,3,-1,-1,7,-1,-1,-1,-1 },
{6,-1,-1,1,9,5,-1,-1,-1 },
{-1,9,8,-1,-1,-1,-1,6,-1 },
{8,-1,-1,-1,6,-1,-1,-1,3 },
{4,-1,-1,8,-1,3,-1,-1,1 },
{7,-1,-1,-1,2,-1,-1,-1,6 },
{-1,6,-1,-1,-1,-1,2,8,-1 },
{-1,-1,-1,4,1,9,-1,-1,5 },
{-1,-1,-1,-1,8,-1,-1,7,9 } };
sudoku = Solve(sudoku, 0, 0);
Console.WriteLine("your sudoku's solution:");
for (int j = 0; j < 9; j++)
for (int i = 0; i < 9; i++)
Console.Write(sudoku[i,j] + " ");
Console.WriteLine("goodbay, and thanks for using the sudoku-solver! see you soon!");
Console.WriteLine("(: (: (:");
public static int[,] Solve(int[,] sudoku, int a, int b)
while (sudoku[i, j] != -1 && !(j == 8 && i == 8))
if (sudoku[i, j] != -1 && i == 8 && j == 8)
int[] options = Options(sudoku, i, j);
int c = CurrentOption(options, 0);
sudoku = Solve(sudoku, 0, j + 1);
sudoku = Solve(sudoku, i + 1, j);
while (sudoku[i, j] == -1)
c = CurrentOption(options, c);
sudoku = Solve(sudoku, 0, j + 1);
sudoku = Solve(sudoku, i + 1, j);
public static int[] Options(int[,] sudoku, int i, int j)
int[] options = new int[9];
temporary = sudoku[i, n];
options[temporary - 1] = -1;
temporary = sudoku[k, j];
options[temporary - 1] = -1;
temporary = sudoku[x, y];
options[temporary - 1] = -1;
public static int CurrentOption(int[] options, int c)
for (int i = c; i < 9 ; i++)