debugging - How do I fix my Python sudoku solver bug? -


this homework


hello. had make python sudoku solver , came with.

http://pastebin.com/jrkaqsed (includes input , output get)

however, when run it, first populate call causes error below. seems add 1 2 cells @ same time.

0 5 9 0 0 0 4 8 3 #current row being tested add, 1 #number add 0 5 #row, column 0 5 9 0 1 1 4 8 3 #row outputs 

i can't figure out why doing that. appreciated.

thank you

edit:

i found bug. generating rowset @ start of each row , therefore didn't know if number had been used.

however, code still doesn't finish sudoku grid

i can't replicate error get, there's problem how read in sudoku grid.

0 5 9 0 0 0 4 8 3 0 0 0 0 0 0 0 1 2 0 1 0 0 2 8 0 0 0 0 9 8 0 7 4 0 2 0 0 4 0 0 8 0 0 3 0 0 7 0 6 3 0 5 4 0 0 0 0 1 6 0 0 5 0 6 2 0 0 0 0 0 0 0 7 3 5 0 0 0 8 6 0 

reading in file way do:

fi = open("sudoku.txt", "r") infile = fi.read() grid = [list(i) in infile.split("\n")] 

this creates grid that's list of lists, not 1 expect. example, here's first line:

['0', ' ', '5', ' ', '9', ' ', '0', ' ', '0', ' ', '0', ' ', '4', ' ', '8', ' ', '3']

instead of reading file string , splitting on newline, can loop through open file object , split each line in split on space.

fi = open("sudoku.txt", "r") grid = [] line in fi:     grid.append([int(i) in line.split(" ")]) 

so think problem related spaces still being present in grid, because after fixing (and problem regarding oldgrid somewhere), solves sudoku.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

How can I fetch data from a web server in an android application? -

jquery - How can I dynamically add a browser tab? -