I'm creating a sudoku solver with backtracking. Now, I need to add 1 to each cell. I'm using a "for" loop:
board = [[[0],[0],[0],[0]],
[[0],[0],[0],[0]],
[[0],[0],[0],[0]],
[[0],[0],[0],[0]]]`
a=0
b=0
x=board[a][b]`
for i in x:
x.append(i+1)
y = [sum(x)]
print(y)
break
board[a][b] = y
What happens is that, if I have a number on the board, like "2", it does the operation of (1+1)+(1+1) +1
, and returns 5 instead of 3. I get 9 from 4 [(1+1)+(1+1)+(1+1)+(1+1)+1)]
, etc.
I'm thinking about solving it by converting "x" from a list to an integer, then adding 1 and then reconverting it in a list.
Any more efficient and time saving ideas?
(I want to keep, if possible, the list structure of "board", but I'm open to any suggestion, of course.)