Fix "failed to solve" comparison in sudoku.py.
authorW. Trevor King <wking@drexel.edu>
Tue, 12 Oct 2010 12:29:42 +0000 (08:29 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 12 Oct 2010 12:29:42 +0000 (08:29 -0400)
Also print puzzle status if execution is interrupted.

assignments/archive/sudoku/soln/sudoku.py

index 126664f408d64567017b9242f5b02ac8694e7bd6..2c086979a862c8af17c2c537b942ebcd4e5806ea 100755 (executable)
@@ -225,7 +225,7 @@ class Sudoku (object):
 
         actions = 0
         while True:
-            start_actions = 0
+            start_actions = actions
             for row in range(9):
                 for col in range(9):
                     if self._puzzle[row][col] == self._empty:
@@ -260,6 +260,9 @@ if __name__ == '__main__':
     s = Sudoku()
     puzzle = sys.stdin.read()
     s.load(puzzle)
-    s.solve()
+    try:
+        s.solve()
+    except KeyboardInterrupt, e:
+        s.status = 'interrupted'
     print >> sys.stderr, s.status
     print s.dump()