Post by (X) on Aug 11, 2023 13:55:27 GMT 1
See scalion's initial post: gb32.proboards.com/post/3649/thread
This is a first draft of code to find the minimum 17 indices required to solve a unique Sudoku puzzle. (ChatGPT3.5)
Private Sub FindMinimumNumbersForSudoku()
Dim grid(8, 8) As Integer
Dim solutionFound As Boolean
Dim minNumbers As Integer
minNumbers = 17 ' Minimum numbers needed for a valid Sudoku
Do
' Clear the grid
ClearGrid grid
' Generate a random Sudoku puzzle
GenerateSudokuPuzzle grid
' Attempt to solve the puzzle
solutionFound = SolveSudoku grid
If solutionFound Then
' Check if the solution meets the minimum numbers requirement
If CountNumbersInGrid(grid) >= minNumbers Then
Exit Do
End If
End If
Loop
End Sub
Private Sub ClearGrid(ByRef grid() As Integer)
Dim i As Integer, j As Integer
For i = 0 To 8
For j = 0 To 8
grid(i, j) = 0
Next j
Next i
End Sub
Private Sub GenerateSudokuPuzzle(ByRef grid() As Integer)
' Implement your logic to generate a Sudoku puzzle here
' You can use various algorithms and techniques
' For simplicity, you can fill a few random cells with valid numbers
' and then attempt to solve the puzzle
End Sub
Private Function SolveSudoku(ByRef grid() As Integer) As Boolean
' Implement your Sudoku solving algorithm here
' You can use backtracking or other techniques
' For simplicity, you can attempt to fill cells one by one,
' checking if the current grid configuration is valid
End Function
Private Function CountNumbersInGrid(ByRef grid() As Integer) As Integer
Dim i As Integer, j As Integer
Dim count As Integer
count = 0
For i = 0 To 8
For j = 0 To 8
If grid(i, j) <> 0 Then
count = count + 1
End If
Next j
Next i
CountNumbersInGrid = count
End Function