


def  _a			(						__UpperCamelCase ):

     # bit count represents no. of bits in the gray code
     if bit_count < 0:
          raise ValueError("""The given input must be positive""" )

     # get the generated string sequence
     a_    :     Tuple										=    gray_code_sequence_string(__UpperCamelCase )
     #
     # convert them to integers
     for i in range(len(__UpperCamelCase ) ):
          a_    :     Any										=    int(sequence[i]  ,  2 )

     return sequence



def  _a			(						__UpperCamelCase ):

     # The approach is a recursive one
     # Base case achieved when either n = 0 or n=1
     if bit_count == 0:
          return ["0"]

     if bit_count == 1:
          return ["0", "1"]

     a_    :     Optional[int]										=    1 << bit_count  # defines the length of the sequence
     # 1<< n is equivalent to 2^n

     # recursive answer will generate answer for n-1 bits
     a_    :     int										=    gray_code_sequence_string(bit_count - 1 )

     a_    :     List[Any]										=    []

     # append 0 to first half of the smaller sequence generated
     for i in range(seq_len // 2 ):
          a_    :     Optional[int]										=    """0""" + smaller_sequence[i]
          sequence.append(__UpperCamelCase )

     # append 1 to second half ... start from the end of the list
     for i in reversed(range(seq_len // 2 ) ):
          a_    :     str										=    """1""" + smaller_sequence[i]
          sequence.append(__UpperCamelCase )

     return sequence


if __name__ == "__main__":
 import doctest

 doctest.testmod()







from heapq import heappop, heappush

import numpy as np



def  _a			(						__UpperCamelCase  ,  __UpperCamelCase  ,  __UpperCamelCase  ,  __UpperCamelCase  ,  ):
     a_			,			a_    :     Any										=    grid.shape
     a_    :     Dict										=    [-1, 1, 0, 0]
     a_    :     List[Any]										=    [0, 0, -1, 1]
     if allow_diagonal:
          dx += [-1, -1, 1, 1]
          dy += [-1, 1, -1, 1]

     a_			,			a_    :     int										=    [(0, source)], set()
     a_    :     Optional[Any]										=    np.full((rows, cols)  ,  np.inf )
     a_    :     Tuple										=    0
     a_    :     Optional[Any]										=    np.empty((rows, cols)  ,  dtype=__UpperCamelCase )
     a_    :     Optional[Any]										=    None

     while queue:
          ((a_)			,			(a_))    :     Any										=    heappop(__UpperCamelCase )
          if (x, y) in visited:
               continue
          visited.add((x, y) )

          if (x, y) == destination:
               a_    :     Tuple										=    []
               while (x, y) != source:
                    path.append((x, y) )
                    a_			,			a_    :     Any										=    predecessors[x, y]
               path.append(__UpperCamelCase )  # add the source manually
               path.reverse()
               return matrix[destination], path

          for i in range(len(__UpperCamelCase ) ):
               a_			,			a_    :     Dict										=    x + dx[i], y + dy[i]
               if 0 <= nx < rows and 0 <= ny < cols:
                    a_    :     List[Any]										=    grid[nx][ny]
                    if next_node == 1 and matrix[nx, ny] > dist + 1:
                         heappush(__UpperCamelCase  ,  (dist + 1, (nx, ny)) )
                         a_    :     List[str]										=    dist + 1
                         a_    :     Union[str, Any]										=    (x, y)

     return np.inf, []


if __name__ == "__main__":
       import doctest

       doctest.testmod()



