



'''simple docstring'''

def 					__lowerCamelCase					(				lowerCAmelCase_  )      ->				list:

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

		return sequence



def 					__lowerCamelCase					(				lowerCAmelCase_  )      ->				list:

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

		_a					:				str				=							[]

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

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

		return sequence


if __name__ == "__main__":
							import doctest

							doctest.testmod()









'''simple docstring'''

from __future__ import annotations

from collections.abc import Iterator
from typing import Any

class      __magic_name__						:







							def __init__(							self :	Dict     ,_UpperCAmelCase :	Any		):
									_a					:				Any				=							data
									_a					:				Node | None				=							None

class      __magic_name__						:







							def __init__(							self :	Any		):
									_a					:				int				=							None
									_a					:				Optional[int]				=							None







							def __iter__(							self :	Optional[int]		):
									_a					:				List[Any]				=							self.head
									while self.head:
											yield node.data
											_a					:				str				=							node.next
											if node == self.head:
													break







							def __len__(							self :	Any		):
									return sum(1 for _ in self		)







							def __repr__(							self :	int		):
									return "->".join(str(_UpperCAmelCase		) for item in iter(self		)		)







							def 							__lowercase      (							self :	Optional[Any]     ,_UpperCAmelCase :	Any		):
									self.insert_nth(len(self		)     ,_UpperCAmelCase		)







							def 							__lowercase      (							self :	str     ,_UpperCAmelCase :	Any		):
									self.insert_nth(0     ,_UpperCAmelCase		)







							def 							__lowercase      (							self :	List[str]     ,_UpperCAmelCase :	int     ,_UpperCAmelCase :	Any		):
									if index < 0 or index > len(self		):
											raise IndexError('list index out of range.'		)
									_a					:				List[str]				=							Node(_UpperCAmelCase		)
									if self.head is None:
											_a					:				Tuple				=							new_node  # first node points itself
											_a					:				int				=							new_node
									elif index == 0:  # insert at head
											_a					:				Any				=							self.head
											_a					:				Tuple				=							new_node
									else:
											_a					:				Any				=							self.head
											for _ in range(index - 1		):
													_a					:				int				=							temp.next
											_a					:				Optional[int]				=							temp.next
											_a					:				int				=							new_node
											if index == len(self		) - 1:  # insert at tail
													_a					:				Optional[int]				=							new_node







							def 							__lowercase      (							self :	List[Any]		):
									return self.delete_nth(0		)







							def 							__lowercase      (							self :	Dict		):
									return self.delete_nth(len(self		) - 1		)







							def 							__lowercase      (							self :	Union[str, Any]     ,_UpperCAmelCase :	int = 0		):
									if not 0 <= index < len(self		):
											raise IndexError('list index out of range.'		)
									_a					:				Optional[int]				=							self.head
									if self.head == self.tail:  # just one node
											_a					:				Optional[int]				=							None
									elif index == 0:  # delete head node
											_a					:				Dict				=							self.tail.next.next
											_a					:				Dict				=							self.head.next
									else:
											_a					:				List[Any]				=							self.head
											for _ in range(index - 1		):
													_a					:				Union[str, Any]				=							temp.next
											_a					:				Optional[int]				=							temp.next
											_a					:				List[str]				=							temp.next.next
											if index == len(self		) - 1:  # delete at tail
													_a					:				int				=							temp
									return delete_node.data







							def 							__lowercase      (							self :	int		):
									return len(self		) == 0



def 					__lowerCamelCase					(				)      ->				None:
		_a					:				int				=							CircularLinkedList()
		assert len(lowerCAmelCase_  ) == 0
		assert circular_linked_list.is_empty() is True
		assert str(lowerCAmelCase_  ) == ""

		try:
				circular_linked_list.delete_front()
				raise AssertionError  # This should not happen
		except IndexError:
				assert True  # This should happen

		try:
				circular_linked_list.delete_tail()
				raise AssertionError  # This should not happen
		except IndexError:
				assert True  # This should happen

		try:
				circular_linked_list.delete_nth(-1  )
				raise AssertionError
		except IndexError:
				assert True

		try:
				circular_linked_list.delete_nth(0  )
				raise AssertionError
		except IndexError:
				assert True

		assert circular_linked_list.is_empty() is True
		for i in range(5  ):
				assert len(lowerCAmelCase_  ) == i
				circular_linked_list.insert_nth(lowerCAmelCase_						,      i + 1  )
		assert str(lowerCAmelCase_  ) == "->".join(str(lowerCAmelCase_  ) for i in range(1						,      6  )  )

		circular_linked_list.insert_tail(6  )
		assert str(lowerCAmelCase_  ) == "->".join(str(lowerCAmelCase_  ) for i in range(1						,      7  )  )
		circular_linked_list.insert_head(0  )
		assert str(lowerCAmelCase_  ) == "->".join(str(lowerCAmelCase_  ) for i in range(0						,      7  )  )

		assert circular_linked_list.delete_front() == 0
		assert circular_linked_list.delete_tail() == 6
		assert str(lowerCAmelCase_  ) == "->".join(str(lowerCAmelCase_  ) for i in range(1						,      6  )  )
		assert circular_linked_list.delete_nth(2  ) == 3

		circular_linked_list.insert_nth(2						,      3  )
		assert str(lowerCAmelCase_  ) == "->".join(str(lowerCAmelCase_  ) for i in range(1						,      6  )  )

		assert circular_linked_list.is_empty() is False


if __name__ == "__main__":
							import doctest

							doctest.testmod()




