week3/crossword/generate.py
def order_domain_values(self, var, assignment):
        """
        Return a list of values in the domain of `var`, in order by
        the number of values they rule out for neighboring variables.
        The first value in the list, for example, should be the one
        that rules out the fewest values among the neighbors of `var`.
        """
        # find all neighbors of the given variable
        neighbors = self.crossword.neighbors(var)
        # traverse over the assignment and see if some neighboring variables are already assigned a word
        for variable in assignment:
            # if variable is in neighbors and in assignment, it already has a value and is not considered a neighbor
            if variable in neighbors:
                neighbors.remove(variable)

        # initialize a result list that will be sorted according to heuristics (least-constraining values)
        result = []
        for variable in self.domains[var]:
            ruled_out = 0  # keep count of how many domain options will be ruled out from neighboring variables
            for neighbor in neighbors:
                for variable_2 in self.domains[neighbor]:
                    overlap = self.crossword.overlaps[var, neighbor]

                    # if there is overlap between variables,
                    # then the one of them can't have that domain anymore
                    if overlap:
                        a, b = overlap
                        if variable[a] != variable_2[b]:
                            ruled_out += 1
            # store the variable with the number of options it will rule out from its neighbors
            result.append([variable, ruled_out])

        # sort all variables by the number of ruled out domain options they will eliminate
        result.sort(key=lambda x: x[1])
        return [i[0] for i in result]

        Return a list of values in the domain of `var`, in order by
        the number of values they rule out for neighboring variables.
        The first value in the list, for example, should be the one
        that rules out the fewest values among the neighbors of `var`.
        
Return a list of values in the domain of `var`, in order by
the number of values they rule out for neighboring variables.
The first value in the list, for example, should be the one
that rules out the fewest values among the neighbors of `var`.
Return a list of values in the domain of ` var ` in order by the number of values they rule out for neighboring variables . The first value in the list for example should be the one that rules out the fewest values among the neighbors of ` var ` .
def order_domain_values(self, var, assignment):
        neighbors = self.crossword.neighbors(var)
        for variable in assignment:
            if variable in neighbors:
                neighbors.remove(variable)
        result = []
        for variable in self.domains[var]:
            ruled_out = 0  
            for neighbor in neighbors:
                for variable_2 in self.domains[neighbor]:
                    overlap = self.crossword.overlaps[var, neighbor]
                    if overlap:
                        a, b = overlap
                        if variable[a] != variable_2[b]:
                            ruled_out += 1
            result.append([variable, ruled_out])
        result.sort(key=lambda x: x[1])
        return [i[0] for i in result]
def order_domain_values ( self , var , assignment ) : neighbors = self . crossword . neighbors ( var ) for variable in assignment : if variable in neighbors : neighbors . remove ( variable ) result = [ ] for variable in self . domains [ var ] : ruled_out = 0 for neighbor in neighbors : for variable_2 in self . domains [ neighbor ] : overlap = self . crossword . overlaps [ var , neighbor ] if overlap : a , b = overlap if variable [ a ] != variable_2 [ b ] : ruled_out += 1 result . append ( [ variable , ruled_out ] ) result . sort ( key = lambda x : x [ 1 ] ) return [ i [ 0 ] for i in result ]
Return a list of values in the domain of `var`, in order by
the number of values they rule out for neighboring variables.
Return a list of values in the domain of ` var ` in order by the number of values they rule out for neighboring variables .
"""
        Return a list of values in the domain of `var`, in order by
        the number of values they rule out for neighboring variables.
        The first value in the list, for example, should be the one
        that rules out the fewest values among the neighbors of `var`.
        """ # find all neighbors of the given variable # traverse over the assignment and see if some neighboring variables are already assigned a word # if variable is in neighbors and in assignment, it already has a value and is not considered a neighbor # initialize a result list that will be sorted according to heuristics (least-constraining values) # keep count of how many domain options will be ruled out from neighboring variables # if there is overlap between variables, # then the one of them can't have that domain anymore # store the variable with the number of options it will rule out from its neighbors # sort all variables by the number of ruled out domain options they will eliminate
self
var
assignment