Sudoku Solver in Python -
Therefore, I am trying to create a function that will take a list of lists, each of which is 9 integers By the number 19, and if he has a valid solution for Sudoku then a boolean returned, now I have been able to solve a part of the problem with checking the rows and columns, but I check three to three boxes I got stuck on the implementation of Here's my code.
alist = [1,2,3,4,5,6,7,8,9] def check sudo oku (grid): a = grid b = grid c = grid d = mistake E = wrong f = mistakes for newlist = [] i in: i.sort () if i == alist: d = true else: d = wrong break for jm in range (9): in b: newlist .append (k) newlist.sort () if i == alist: e = true newlist = [] and: e = wrong break if d == true and e == true: return right second: return false Actually, I had to test all the three factors needed to be true, then return the truth if all The truth is white, then false false return any help? Not sure that this is your problem, but there is a very clear problem with this code:
a = grid B = grid C = grid It seems that you think that it creates 3 copies of the grid, but it is not. It makes three different references of the same object. This means that your i.sort () on a will later affect the argument on b . What exactly should you copy the object? It is a nested list, making it a little tricky, but the library function is accompanied by a deeper cavity:
a = copy.deepcopy (grid) b = copy.deepcopy (grid) c = copy.deepcopy (grid)
Comments
Post a Comment