def recFCH(matrix, valM, cons, row, col, minus, max): global returns, flag count = countValues(matrix) consItem = checkRegConsS(matrix, row, col) consItem = consItem[minus:] if flag: return elif findEmptyH(matrix): returns += 1 elif [row, col] in valM: itemSet(matrix, cons, row, col, minus, max, consItem[0], valM) returns += 1 elif len(consItem) == 0: returns += 1 elif count == max - 1: matrix.itemset((row, col), consItem[0]) if checkConsS(matrix, cons): flag = True returns += 1 return else: matrix.itemset((row, col), 0) return else: itemSet(matrix, cons, row, col, minus, max, consItem[0], valM)
def findEmptyH(matrix): for i, j in itertools.product(range(len(matrix)), range(len(matrix))): if matrix[i][j] != 0: pass else: if len(checkRegConsS(matrix, i, j)) == 0: return True return False
def findConCell(matrix, cons): x, y = len(matrix) + 1, len(matrix) + 1 minCons = len(matrix) for row, col in itertools.product(range(len(matrix)), range(len(matrix))): constraints = len(checkRegConsS(matrix, row, col)) if minCons > constraints > 0 and matrix[row][col] == 0: minCons = constraints x = row y = col return x, y