143 views
1 vote
General Instructions:

Create a program that will generate a solved sudoku board from a blank sudoku board.
Each number must be unique in each row, column and the 3x3 grid (cell) it belongs to.
The number of attempts must be counted.
The number of attempts must be less than 100,000.
You must use an n-dimensional object (array) where n > 1.
You must use at least 1 of any list variation.
Restrictions (Breaking any of the restrictions will lead to an automatic failure):
No OOP. Aside from the standard generated OOP method which is 'static void main(string[] args)' there should be no other classes and methods.
Each number in each 3x3 grid (cell) must be uniquely generated.

1 Answer

3 votes

Final answer:

To generate a solved sudoku board from a blank board, you can use a backtracking algorithm that recursively tries different numbers in each empty cell until a valid solution is found.

Step-by-step explanation:

Sudoku is a popular puzzle game where the goal is to fill a grid with numbers in a way that each row, column, and 3x3 grid contains all numbers from 1 to 9 without repetition. To generate a solved sudoku board, you can use a backtracking algorithm that recursively tries different numbers in each empty cell until a valid solution is found. In this case, you can use a 2-dimensional array to represent the sudoku board.

Here's a high-level explanation of how you can approach this problem:

  1. Create a function that checks if a number is valid in a given cell, considering the constraints of rows, columns, and 3x3 grids.
  2. Create a recursive function that starts from the first empty cell in the board and tries different numbers until a valid solution is found or all numbers have been tried.
  3. If a valid number is found, move on to the next empty cell, and repeat step 2.
  4. If no valid number is found for a cell, backtrack to the previous cell and try a different number.
  5. Repeat steps 3 and 4 until all empty cells have been filled or the number of attempts exceeds 100,000.

User Neoheurist
by
7.2k points