2020/20.py
def turbulence(lines) -> Optional[int]:
        """
        Returns the turbulence if there are monsters in this orientation. It's
        guaranteed that there will be only one configuration that has monsters, so if
        there are no monsters, then this is not the correct orientation.
        """
        R = len(lines)
        C = len(lines[0])
        for r0 in range(R):
            for c0 in range(C):
                is_seamonster = True

                for r, c in it.product(range(seamonster_r), range(seamonster_c)):
                    if debug:
                        print(r, c, r0 + r, c0 + c)
                    if not (0 <= r0 + r < R and 0 <= c0 + c < C):
                        is_seamonster = False
                        break
                    if seamonster[r][c] == "#" and lines[r0 + r][c0 + c] not in "#O":
                        is_seamonster = False
                        break

                if is_seamonster:
                    for r, c in it.product(range(seamonster_r), range(seamonster_c)):
                        if seamonster[r][c] == "#":
                            lines[r0 + r][c0 + c] = "O"

        t = 0
        anyseamonster = False
        for l in lines:
            for c in l:
                if c == "#":
                    t += 1
                if c == "O":
                    anyseamonster = True

        if anyseamonster and debug:
            print("SEAMONSTERS:")
            for row in lines:
                print("".join(row))
        return t if anyseamonster else None

        Returns the turbulence if there are monsters in this orientation. It's
        guaranteed that there will be only one configuration that has monsters, so if
        there are no monsters, then this is not the correct orientation.
        
Returns the turbulence if there are monsters in this orientation. It's
guaranteed that there will be only one configuration that has monsters, so if
there are no monsters, then this is not the correct orientation.
Returns the turbulence if there are monsters in this orientation . It ' s guaranteed that there will be only one configuration that has monsters so if there are no monsters then this is not the correct orientation .
def turbulence(lines) -> Optional[int]:
        R = len(lines)
        C = len(lines[0])
        for r0 in range(R):
            for c0 in range(C):
                is_seamonster = True
                for r, c in it.product(range(seamonster_r), range(seamonster_c)):
                    if debug:
                        print(r, c, r0 + r, c0 + c)
                    if not (0 <= r0 + r < R and 0 <= c0 + c < C):
                        is_seamonster = False
                        break
                    if seamonster[r][c] == "#" and lines[r0 + r][c0 + c] not in "#O":
                        is_seamonster = False
                        break
                if is_seamonster:
                    for r, c in it.product(range(seamonster_r), range(seamonster_c)):
                        if seamonster[r][c] == "#":
                            lines[r0 + r][c0 + c] = "O"
        t = 0
        anyseamonster = False
        for l in lines:
            for c in l:
                if c == "#":
                    t += 1
                if c == "O":
                    anyseamonster = True
        if anyseamonster and debug:
            print("SEAMONSTERS:")
            for row in lines:
                print("".join(row))
        return t if anyseamonster else None
def turbulence ( lines ) -> Optional [ int ] : R = len ( lines ) C = len ( lines [ 0 ] ) for r0 in range ( R ) : for c0 in range ( C ) : is_seamonster = True for r , c in it . product ( range ( seamonster_r ) , range ( seamonster_c ) ) : if debug : print ( r , c , r0 + r , c0 + c ) if not ( 0 <= r0 + r < R and 0 <= c0 + c < C ) : is_seamonster = False break if seamonster [ r ] [ c ] == "#" and lines [ r0 + r ] [ c0 + c ] not in "#O" : is_seamonster = False break if is_seamonster : for r , c in it . product ( range ( seamonster_r ) , range ( seamonster_c ) ) : if seamonster [ r ] [ c ] == "#" : lines [ r0 + r ] [ c0 + c ] = "O" t = 0 anyseamonster = False for l in lines : for c in l : if c == "#" : t += 1 if c == "O" : anyseamonster = True if anyseamonster and debug : print ( "SEAMONSTERS:" ) for row in lines : print ( "" . join ( row ) ) return t if anyseamonster else None
Returns the turbulence if there are monsters in this orientation.
Returns the turbulence if there are monsters in this orientation .
"""
        Returns the turbulence if there are monsters in this orientation. It's
        guaranteed that there will be only one configuration that has monsters, so if
        there are no monsters, then this is not the correct orientation.
        """
lines