


"""simple docstring"""





def    _snake_case  (  _snake_case :	int	):

      # 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
      lowerCAmelCase    :		Optional[int]				=      gray_code_sequence_string(_snake_case	)
      #
      # convert them to integers
      for i in range(len(_snake_case	)	):
            lowerCAmelCase    :		Any				=      int(sequence[i]       ,      2	)

      return sequence


def    _snake_case  (  _snake_case :	int	):

      # 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"]

      lowerCAmelCase    :		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
      lowerCAmelCase    :		List[Any]				=      gray_code_sequence_string(bit_count - 1	)

      lowerCAmelCase    :		int				=      []

      # append 0 to first half of the smaller sequence generated
      for i in range(seq_len // 2	):
            lowerCAmelCase    :		str				=      '''0''' + smaller_sequence[i]
            sequence.append(_snake_case	)

      # append 1 to second half ... start from the end of the list
      for i in reversed(range(seq_len // 2	)	):
            lowerCAmelCase    :		int				=      '''1''' + smaller_sequence[i]
            sequence.append(_snake_case	)

      return sequence


if __name__ == "__main__":
 import doctest

 doctest.testmod()










'''simple docstring'''







from heapq import heappop, heappush

import numpy as np





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase				,			)      ->       tuple[float | int, list[tuple[int, int]]]:
							lowerCamelCase__  ,		lowerCamelCase__					:	Union[str, Any]         =       grid.shape
							lowerCamelCase__					:	List[str]         =       [-1, 1, 0, 0]
							lowerCamelCase__					:	Dict         =       [0, 0, -1, 1]
							if allow_diagonal:
														dx += [-1, -1, 1, 1]
														dy += [-1, 1, -1, 1]

							lowerCamelCase__  ,		lowerCamelCase__					:	Any         =       [(0, source)], set()
							lowerCamelCase__					:	Tuple         =       np.full((rows, cols)				,			np.inf      )
							lowerCamelCase__					:	List[str]         =       0
							lowerCamelCase__					:	Optional[int]         =       np.empty((rows, cols)				,			dtype=UpperCamelCase      )
							lowerCamelCase__					:	str         =       None

							while queue:
														((lowerCamelCase__)  ,		(lowerCamelCase__))					:	List[str]         =       heappop(UpperCamelCase      )
														if (x, y) in visited:
																					continue
														visited.add((x, y)      )

														if (x, y) == destination:
																					lowerCamelCase__					:	Optional[int]         =       []
																					while (x, y) != source:
																												path.append((x, y)      )
																												lowerCamelCase__  ,		lowerCamelCase__					:	List[Any]         =       predecessors[x, y]
																					path.append(UpperCamelCase      )  # add the source manually
																					path.reverse()
																					return matrix[destination], path

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

							return np.inf, []


if __name__ == "__main__":
			import doctest

			doctest.testmod()

