week3/crossword/generate.py
def select_unassigned_variable(self, assignment):
        """
        Return an unassigned variable not already part of `assignment`.
        Choose the variable with the minimum number of remaining values
        in its domain. If there is a tie, choose the variable with the highest
        degree. If there is a tie, any of the tied variables are acceptable
        return values.
        """
        # initialize a list of potential variables to consider with heuristics (minimum remaining value and degree)
        potential_variables = []
        for variable in self.crossword.variables:  # iterate over all variables in the crossword
            if variable not in assignment:  # if the variable is unassigned (meaning it is not in assignment)
                # then add it to potentials with the number of domain options (minimum remaining value heuristic)
                # and number of neighbors (degree heuristic)
                potential_variables.append([variable, len(self.domains[variable]), len(self.crossword.neighbors(variable))])

        # sort potential variables by the number of domain options (ascending) and number of neighbors (descending)
        if potential_variables:
            potential_variables.sort(key=lambda x: (x[1], -x[2]))
            return potential_variables[0][0]

        # If there are no potential variables, simply return None
        return None

        Return an unassigned variable not already part of `assignment`.
        Choose the variable with the minimum number of remaining values
        in its domain. If there is a tie, choose the variable with the highest
        degree. If there is a tie, any of the tied variables are acceptable
        return values.
        
Return an unassigned variable not already part of `assignment`.
Choose the variable with the minimum number of remaining values
in its domain. If there is a tie, choose the variable with the highest
degree. If there is a tie, any of the tied variables are acceptable
return values.
Return an unassigned variable not already part of ` assignment ` . Choose the variable with the minimum number of remaining values in its domain . If there is a tie choose the variable with the highest degree . If there is a tie any of the tied variables are acceptable return values .
def select_unassigned_variable(self, assignment):
        potential_variables = []
        for variable in self.crossword.variables:  
            if variable not in assignment:  
                potential_variables.append([variable, len(self.domains[variable]), len(self.crossword.neighbors(variable))])
        if potential_variables:
            potential_variables.sort(key=lambda x: (x[1], -x[2]))
            return potential_variables[0][0]
        return None
def select_unassigned_variable ( self , assignment ) : potential_variables = [ ] for variable in self . crossword . variables : if variable not in assignment : potential_variables . append ( [ variable , len ( self . domains [ variable ] ) , len ( self . crossword . neighbors ( variable ) ) ] ) if potential_variables : potential_variables . sort ( key = lambda x : ( x [ 1 ] , - x [ 2 ] ) ) return potential_variables [ 0 ] [ 0 ] return None
Return an unassigned variable not already part of `assignment`.
Return an unassigned variable not already part of ` assignment ` .
"""
        Return an unassigned variable not already part of `assignment`.
        Choose the variable with the minimum number of remaining values
        in its domain. If there is a tie, choose the variable with the highest
        degree. If there is a tie, any of the tied variables are acceptable
        return values.
        """ # initialize a list of potential variables to consider with heuristics (minimum remaining value and degree) # iterate over all variables in the crossword # if the variable is unassigned (meaning it is not in assignment) # then add it to potentials with the number of domain options (minimum remaining value heuristic) # and number of neighbors (degree heuristic) # sort potential variables by the number of domain options (ascending) and number of neighbors (descending) # If there are no potential variables, simply return None
self
assignment