So, I'm trying to create a sudoku solver. Now, I want to check if a number is in it's line, column and square. Can I do it without introducing the line, column and square as function parameters? Is there any way to select the lists that contain an item? Here's my code:
sudoku = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
line1 = [sudoku[0],sudoku[1],sudoku[2],sudoku[3]]
column1 = [sudoku[0],sudoku[4],sudoku[8],sudoku[12]]
square1 = [sudoku[0],sudoku[1],sudoku[4],sudoku[5]]
def sudoku_cellsolver(x):
while sudoku[x] == 0:
number = sudoku[x]+1
if number not in #"List, column, square":
sudoku[x] = number
else:
number = number + 1
#Check another time, etc
while sudoku[x] != 0:
sudoku_cellsolver(x+1)
Any help welcomed. I also have an error when the second branch gets out of range, but I will deal with it later.
EDIT:
Pseudocode:
sudoku = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
l1 = {sudoku[0],sudoku[1],sudoku[2],sudoku[3]} #Converted to set
c1 = {sudoku[0],sudoku[4],sudoku[8],sudoku[12]} #Converted to set
sq1 = {sudoku[0],sudoku[1],sudoku[4],sudoku[5]} #Converted to set
group0 = [l1 | c1 | sq1] #Concatenation of sets
def sudoku_cellsolver(x,group):
if sudoku[x] == 0:
number = sudoku[x]+1
if number not in group:
sudoku[x] = number
The main problem is that I can't use a loop to solve one gap after another because I can't modify the parameter "group0" so that it changes to "group1" inside the function, something I can do with "sudoku[0]" to "sudoku[1]" using the "sudoku[x] = sudoku[x+1]".
If there's no way to change from "group0" to "group1" from inside the function, I'll have to define 16 almost-equal functions where only the "group" changes, and executing them from another function that uses an "if" statement to decide which one of the 16 functions is executed.