This routine is structurally very similar to Section 5.15, “SudokuSolver.__usedInRow():
Eliminate digits by row”. The only difference is that
we step through the rows of the column containing
x, skipping the row containing
x.
# - - - S u d o k u S o l v e r . _ _ u s e d I n C o l u m n
def __usedInColumn ( self, x ):
"""What digits are used elsewhere in the column containing x?
[ x is an integer in [0,BOARD_L) ->
return a 9-element bitmap whose elements are true
iff the corresponding digit is used elsewhere in
the column containing board position x ]
"""
#-- 1 --
# [ rx := the row index of board position x
# cx := the column index of board position x
# result := a list of MAT_L zeroes ]
rx, cx = self.__xToRowCol ( x )
result = [0] * MAT_L
Again, we skip over cell x so
that our result doesn't depend on the state of the cell
currently under consideration.
#-- 2 --
# [ result := result with elements corresponding to
# digits found in column cx (except for row rx) ]
for row in range(MAT_L):
#-- 2 body --
# [ if (row != rx) and
# (self has a nonzero value D in cell (rx, col) ->
# result[D-1] := 1
# else ->
# I ]
if row != rx:
cell = self.get(row, cx)
if cell != EMPTY:
result[cell-1] = 1
#-- 3 --
return result