# - - - S u d o k u S o l v e r . w r i t e - - -
def write ( self, outFile ):
"""Write the puzzle state as plain text.
Output format (minus the enclosing box):
+---------------------+
|7 2 . . . 5 1 . .|
|. 1 5 9 8 . 4 . .|
|. 8 . . . 1 . . 6|
| |
|. 4 . . 3 . 6 . 5|
|3 . . 6 . 2 . . 7|
|9 . 1 . 7 . . 2 .|
| |
|5 . . 7 . . . 9 .|
|. . 2 . 9 6 3 5 .|
|. . 4 2 . . . 6 8|
+---------------------+
"""
To generate the output, we run two stacked loops.
The outer loop iterates over the rows of the puzzle. It adds an extra blank line between rows 2 and 3 and between rows 5 and 6 (counting from zero).
The inner loop iterates over the columns. It adds
a space between each item, and adds extra spaces
after columns 2 and 5. That loop resides in
Section 5.10, “SudokuSolver.writeRow():
Write one row of the puzzle”.
#-- 1 --
for rowx in range(MAT_L):
#-- 1 body --
# [ rowx is in [0,MAT_L) ->
# outFile +:= a representation of row rowx of self ]
#-- 1.1 --
# [ if ( ( rowx > 0 ) and
# ( rowx % SUBMAT_L ) == 0 ) ) ->
# outFile +:= an empty line
# else -> I ]
if ( ( rowx > 0 ) and
( ( rowx % SUBMAT_L ) == 0 ) ):
print >> outFile
#-- 1.2 --
# [ outFile +:= a representation of row rowx of self ]
self.writeRow ( outFile, rowx )
For a discussion of the verification of this method,
see Section 7.4, “Inspection: SudokuSolver.write()”.