function computeValid() % % This function computes the valid matrix, which is a data structure that % we use to keep track of the valid values % for this cell. For every cell on the board, there is a vector of % 8 values (representing numerals 1-9). It is 1 if valid to write this % number in this cell, 0 if it is not valid, and -1 if unassigned % % Author: Greg Coombe % Date: Nov 29, 2005 % global B; global Valid; global RegionTable; % For each element on the board, mark off all of the cells in % that rows and columns. For example, if there is a 5 in cell 3,6, % then we mark off all of the valid 5's in row 3, and all of the % valid 5's in column 6. for i=1:9, for j=1:9, % if there is an assigned value here if ( B(i,j) ~= 0 ) value = B(i,j); % mark off row Valid( :, j, value ) = 0; % mark off column Valid( i, :, value ) = 0; % mark off region region_i = RegionTable(i,:); region_j = RegionTable(j,:); Valid( region_i, region_j, value ) = 0; % Also mark off all the possibilites for this cell Valid( i, j, :) = zeros(1,9); end end %for end %for