week3/crossword/generate.py
def revise(self, x, y):
        """
        USE PSEUDOCODE FROM THE LECTURE NODES

        Make variable `x` arc consistent with variable `y`.
        To do so, remove values from `self.domains[x]` for which there is no
        possible corresponding value for `y` in `self.domains[y]`.

        Return True if a revision was made to the domain of `x`; return
        False if no revision was made.
        """
        revised = False  # set revised to false to see if any consistency will be set
        overlap = self.crossword.overlaps[x, y]  # find the overlap between two nodes (place in grid that they share)

        if overlap:
            v1, v2 = overlap
            xs_to_remove = set()  # store all x domains to remove
            for x_i in self.domains[x]:
                overlaps = False  # find if there is x variable that overlaps with y variable
                for y_j in self.domains[y]:
                    if x_i != y_j and x_i[v1] == y_j[v2]:
                        overlaps = True
                        break
                if not overlaps:  # if there is no overlap in variables, remove x variable
                    xs_to_remove.add(x_i)
            if xs_to_remove:  # if there are x variables to remove from the x domain, remove
                self.domains[x] = self.domains[x].difference(xs_to_remove)
                revised = True  # set revised to true to shows that a revision was made

        return revised

        USE PSEUDOCODE FROM THE LECTURE NODES

        Make variable `x` arc consistent with variable `y`.
        To do so, remove values from `self.domains[x]` for which there is no
        possible corresponding value for `y` in `self.domains[y]`.

        Return True if a revision was made to the domain of `x`; return
        False if no revision was made.
        


Return True if a revision was made to the domain of `x`; return
False if no revision was made.
Return True if a revision was made to the domain of ` x ` ; return False if no revision was made .
def revise(self, x, y):
        revised = False  
        overlap = self.crossword.overlaps[x, y]  
        if overlap:
            v1, v2 = overlap
            xs_to_remove = set()  
            for x_i in self.domains[x]:
                overlaps = False  
                for y_j in self.domains[y]:
                    if x_i != y_j and x_i[v1] == y_j[v2]:
                        overlaps = True
                        break
                if not overlaps:  
                    xs_to_remove.add(x_i)
            if xs_to_remove:  
                self.domains[x] = self.domains[x].difference(xs_to_remove)
                revised = True  
        return revised
def revise ( self , x , y ) : revised = False overlap = self . crossword . overlaps [ x , y ] if overlap : v1 , v2 = overlap xs_to_remove = set ( ) for x_i in self . domains [ x ] : overlaps = False for y_j in self . domains [ y ] : if x_i != y_j and x_i [ v1 ] == y_j [ v2 ] : overlaps = True break if not overlaps : xs_to_remove . add ( x_i ) if xs_to_remove : self . domains [ x ] = self . domains [ x ] . difference ( xs_to_remove ) revised = True return revised
USE PSEUDOCODE FROM THE LECTURE NODES
Make variable `x` arc consistent with variable `y`.
USE PSEUDOCODE FROM THE LECTURE NODES Make variable ` x ` arc consistent with variable ` y ` .
"""
        USE PSEUDOCODE FROM THE LECTURE NODES

        Make variable `x` arc consistent with variable `y`.
        To do so, remove values from `self.domains[x]` for which there is no
        possible corresponding value for `y` in `self.domains[y]`.

        Return True if a revision was made to the domain of `x`; return
        False if no revision was made.
        """ # set revised to false to see if any consistency will be set # find the overlap between two nodes (place in grid that they share) # store all x domains to remove # find if there is x variable that overlaps with y variable # if there is no overlap in variables, remove x variable # if there are x variables to remove from the x domain, remove # set revised to true to shows that a revision was made
self
x
y