Rev 408 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/env python__author__ = "Ira W. Snyder (devel@irasnyder.com)"__copyright__ = "Copyright (c) 2006, Ira W. Snyder (devel@irasnyder.com)"__license__ = "GNU GPL v2 (or, at your option, any later version)"import timefrom PyCompat import *from SudokuPuzzle import SudokuPuzzle, solvefrom Menu import Menudef input_puzzle (puzzle):print 'Enter a row at a time. Use \'e\' for empty squares.'for i in xrange(9):e = raw_input('line %d: ' % i)temp = e.split ()count = 0for j in temp:try:puzzle[i,count].set_value (int(j))except:passcount += 1def input_and_solve_puzzle ():puzzle = SudokuPuzzle ()# Input the Puzzleinput_puzzle (puzzle)# Solve the Puzzletstart = time.time ()solution = solve (puzzle)tend = time.time ()# Print the Solutionprint '\nThe solution is:'print str(solution)print 'Took %s seconds to solve' % str(tend - tstart)def main ():m = Menu (autorun=True)m.add_entry ('1', 'Enter & Solve Sudoku Puzzle', input_and_solve_puzzle)m.add_entry ('2', 'Quit', sys.exit)# Run the menu forever, until it auto-exitswhile True:m.run_menu ()if __name__ == '__main__':main ()