using System; namespace ClassExamples { class SudokuMaker { public static int[,] createSudoku(int emptyPositions) { int[,] sudoku = new int[9,9]; int temp = 0; int i,j; for (i=0; i<9; i++) { for (j=0; j<9; j++) { temp = j + i*3 + (i/3 + 1) + 1; sudoku[i,j] = temp - (9 * (temp/9)) + 1; } } Random rand = new Random(); int removed = 0; while (removed < emptyPositions) { i = rand.Next(9); j = rand.Next(9); if (sudoku[i,j] > 0) { sudoku[i,j] = -1; removed++; } } return sudoku; } public static void Main(string[] args) { int[,] sudoku = createSudoku(40); printSudoku(sudoku); } public static void printSudoku(int[,] sudoku) { for (int i=0; i<9; i++) { if (i%3 == 0) { Console.WriteLine("============================="); } Console.Write("|| "); for (int j=0; j<9; j++) { if (sudoku[i,j] > 0) { Console.Write(sudoku[i,j]); } else { Console.Write(" "); } if ((j+1)%3 != 0) { Console.Write(" "); } else { Console.Write(" || "); } } Console.WriteLine(); } Console.WriteLine("============================="); } } }