ewall / sudokusolver.py

Coding exercise: solve a 9x9 matrix Sudoku puzzle

This URL has Read+Write access

name age message
file README Loading commit data...
file SudokuSolver.py
README
Help on class SudokuPuzzle in module __main__:

class SudokuPuzzle
 |  This class represents and solves a 9x9 matrix Sudoku puzzle.
 |  
 |  Puzzles are 9x9 matrices as nested lists, like this:
 |      puzzle = [ [0,0,0, 0,0,0, 0,0,0],
 |                 [0,0,0, 0,0,0, 0,0,0],
 |                 [0,0,0, 0,0,0, 0,0,0],
 |                 [0,0,0, 0,0,0, 0,0,0],
 |                 [0,0,0, 0,0,0, 0,0,0],
 |                 [0,0,0, 0,0,0, 0,0,0],
 |                 [0,0,0, 0,0,0, 0,0,0],
 |                 [0,0,0, 0,0,0, 0,0,0],
 |                 [0,0,0, 0,0,0, 0,0,0] ]
 |  
 |  A few notes on the variables in the code...
 |  x will always represent the x-axis position / column number ordinally
 |  y will always represent the y-axis position / row number ordinally
 |  z will always represent the number of the square,
 |      assigned 1-9 from left-to-right and top-to-bottom
 |  
 |  Methods defined here:
 |  
 |  __init__(self, puzzle)
 |      you must pass in a 9x9 nested-list matrix as the puzzle
 |  
 |  checkAllPoints(self)
 |      loop through all points, return True if puzzle is solved
 |  
 |  checkPoint(self, x, y)
 |      calculate a single coordinate,
 |      assign the value if an answer is found,
 |      return True if this point is done
 |  
 |  col(self, x)
 |      return ordinal column of puzzle as a set
 |  
 |  point(self, x, y)
 |      return value at a coordinate in the puzzle
 |  
 |  prettyPrint(self)
 |      stdout printing of the puzzle
 |  
 |  row(self, y)
 |      return ordinal row of puzzle as a set
 |  
 |  setPoint(self, x, y, value)
 |      set the value at the given coordinates
 |  
 |  solve(self)
 |      keep checking all points until either it's solved
 |      or 1000 loops have passed and we can't solve it
 |  
 |  square(self, z)
 |      return ordinal square number of puzzle as a set
 |  
 |  squareNum(self, x, y)
 |      return square number from the given coordinates
 |  
 |  tripleCheck(self)
 |      go over each row, column, and square to be sure it's solved
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  fullset = set([1, 2, 3, 4, 5, 6, ...])
 |  
 |  puzzle = None