Brute force Algorithm for creation of Sudoku Board

前端 未结 6 1883
我寻月下人不归
我寻月下人不归 2021-02-09 12:59

What I am developing is that initially the entire sudoku board is empty. One of the random cells(out of 81) is filled with a random value(1-9).

Now I want to fill all

6条回答
  •  日久生厌
    2021-02-09 13:54

    This simple random walk algorithm should work too (but is inefficient- use at your own risk!!!):

    EDIT: - added fix for unresolvable solutions.

    For each empty cell in grid
        array = Get_Legal_Numbers_for_cell(row,col);
        If (array is empty) {
            Clear_All_cells()
        } else {
            number = Random_number_from(array);
            Put_Number_in_Cell(number);
        }
    

    EDIT 2

    If someone are interested here are described methods for solving sudoku with random-based search.

提交回复
热议问题