function strategy1() % % Strategy #1: % % If the only possiblities for a value are all % in the same row (or column), then we can mark off % that row (or col) in the other regions % % % Author: Greg Coombe % Date: June 5, 2006 % % the board and the choices global B; global Valid; % Get the row and col number for regions rrow = inline('mod((x-1),3)+1'); rcol = inline('floor((x-1)/3)+1'); % Loop over every region, and check whether the only valid choices % are in the same row or column. If so, then that for i=1:3:9, for j=1:3:9, region_valid = Valid(i:i+2,j:j+2,:); for v=1:9, % Find the valid choices in this region pts = find(region_valid(:,:,v)); if ( length(pts) >= 2 ) % Convert to rows and columns rr = rrow(pts); rc = rcol(pts); % If the only possiblities for this value are all % in the same row (or column), then we can mark off % that row (or col) in the other regions if ( all(rr == rr(1)) ) % Mark off the valid choices from the other % regions for this row Valid(i-1+rr(1),:,v) = 0; Valid(i-1+rr(1),j-1+rc, v) = 1; elseif ( all(rc == rc(1)) ) % Mark off the valid choices from the other % regions for this column Valid(:,j-1+rc(1),v) = 0; Valid(i-1+rr,j-1+rc(1),v) = 1; end end end end end