# 11-11-2022 LeetCode 37. Sudoku Solver # https://leetcode.com/problems/sudoku-solver/description/ # Shall we attempt to use 9 digit binary to represent possibilities? # A 1 being possible, 0 meaning not. # Shall we assume we're being passed particularly simple sudoku puzzles # as the input: ones where iteratively eliminating possibilities on a # row, col, box basis is guarenteed to work? There are of course significantly # more difficult classses of puzzles that require advanced techniques. # Oh great... we are not only given basic puzzles # Id say the next most advanced technique after basic elimination is pair-sets: # If n squares share n posibilities within a grouping (row, col, box), then no # other square within that grouping can contain any of the shared possibilites- # they are bound to the n squares. Hopefully this technique isnt needed to solve # this, as thats getting a bit out there. Still basic, but a bit of coding... # After 90 minutes I've gotten it to work!!! For the first test case only... # The logic is there and I THINK it is indeed running through and removing # possibilities for every change made/squre solved. I guess the test cases include # MORE than the most basic sudoku puzzles. Running the following test case: # [[".",".","9","7","4","8",".",".","."],["7",".",".",".",".",".",".",".","."],[".","2",".","1",".","9",".",".","."],[".",".","7",".",".",".","2","4","."],[".","6","4",".","1",".","5","9","."],[".","9","8",".",".",".","3",".","."],[".",".",".","8",".","3",".","2","."],[".",".",".",".",".",".",".",".","6"],[".",".",".","2","7","5","9",".","."]] # And printing a whacky mixed "solved squares and bin(possibilities)" I can see squares that have multiple possibilites # BUT may be the only cell available for a given number for a row, col, or box. # I guess I need to implement the NEXT level of logic. When we run out of changed squares, # iterate through all remaining unsolved cells: for each row, col, box, IF the cell is the # only possibility for a given number, change it to that number and add it to the changed stack # STILL NOT ENOUGH! I guess we will have to implement the N sets of N possibilities per group # elimination method, but frankly I'm tire of this problem and peeking at the solution it # looks as if that may STILL not be enough. The given answer is "use backtracking", which baasically # amounts to having the computer guess and check. Very frustrating that this is the listed solution. # Its an lesson in trying to outhink the problem: I've wasted a number of hourse trying to # algorithmically solve the problem as I would do it on paper. A computer can guess and check its # way through, quickly so why bother with clever algos? Its really disappointing. # Do not return anything, modify board in-place instead class Solution: def solveSudoku(self, board: List[List[str]]) -> None: # print original board for clarity: # for row in board: # print(row) # Yes, these may unnecessary/clumsy, but I'm building as I go... We'll see what I use # Surely there is an elegant way to do this simply: 1<