
"""simple docstring"""




import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


A__      :	Union[str, Any]          =    False
try:
    A__      :	Optional[int]          =    _is_package_available("""google.colab""")
except ModuleNotFoundError:
    pass







@input.register
class   _lowercase						:


     '''simple docstring'''





     def __init__(      self ,			__UpperCamelCase = None ,			__UpperCamelCase = []  )->					Any:
          UpperCAmelCase__							: Union[str, Any] 							=						0
          UpperCAmelCase__							: Optional[Any] 							=						choices
          UpperCAmelCase__							: Optional[int] 							=						prompt
          if sys.platform == "win32":
               UpperCAmelCase__							: List[Any] 							=						"*"
          else:
               UpperCAmelCase__							: Optional[int] 							=						"➔ "



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase ,			__UpperCamelCase = ""  )->					Any:
          if sys.platform != "win32":
               writeColor(self.choices[index] ,			32 ,			__UpperCamelCase  )
          else:
               forceWrite(self.choices[index] ,			__UpperCamelCase  )



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase  )->					int:
          if index == self.position:
               forceWrite(F" {self.arrow_char} "  )
               self.write_choice(__UpperCamelCase  )
          else:
               forceWrite(F"    {self.choices[index]}"  )
          reset_cursor()



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase ,			__UpperCamelCase = 1  )->					List[str]:
          UpperCAmelCase__							: Dict 							=						self.position
          if direction == Direction.DOWN:
               if self.position + 1 >= len(self.choices  ):
                    return
               self.position += num_spaces
          else:
               if self.position - 1 < 0:
                    return
               self.position -= num_spaces
          clear_line()
          self.print_choice(__UpperCamelCase  )
          move_cursor(__UpperCamelCase ,			direction.name  )
          self.print_choice(self.position  )



     @input.mark(KEYMAP["up"]  )
     def  lowerCAmelCase__       (      self  )->					int:
          self.move_direction(Direction.UP  )



     @input.mark(KEYMAP["down"]  )
     def  lowerCAmelCase__       (      self  )->					Optional[int]:
          self.move_direction(Direction.DOWN  )



     @input.mark(KEYMAP["newline"]  )
     def  lowerCAmelCase__       (      self  )->					Tuple:
          move_cursor(len(self.choices  ) - self.position ,			"DOWN"  )
          return self.position



     @input.mark(KEYMAP["interrupt"]  )
     def  lowerCAmelCase__       (      self  )->					str:
          move_cursor(len(self.choices  ) - self.position ,			"DOWN"  )
          raise KeyboardInterrupt



     @input.mark_multiple(*[KEYMAP[str(__UpperCamelCase  )] for number in range(10  )]  )
     def  lowerCAmelCase__       (      self  )->					str:
          UpperCAmelCase__							: Any 							=						int(chr(self.current_selection  )  )
          UpperCAmelCase__							: Optional[int] 							=						index - self.position
          if index == self.position:
               return
          if index < len(self.choices  ):
               if self.position > index:
                    self.move_direction(Direction.UP ,			-movement  )
               elif self.position < index:
                    self.move_direction(Direction.DOWN ,			__UpperCamelCase  )
               else:
                    return
          else:
               return



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase = 0  )->					Tuple:
          if self.prompt:
               linebreak()
               forceWrite(self.prompt ,			"\n"  )
               if in_colab:
                    forceWrite("Please input a choice index (starting from 0), and press enter" ,			"\n"  )
               else:
                    forceWrite("Please select a choice using the arrow or number keys, and selecting with enter" ,			"\n"  )
          UpperCAmelCase__							: Optional[Any] 							=						default_choice
          for i in range(len(self.choices  )  ):
               self.print_choice(__UpperCamelCase  )
               forceWrite("\n"  )
          move_cursor(len(self.choices  ) - self.position ,			"UP"  )
          with cursor.hide():
               while True:
                    if in_colab:
                         try:
                              UpperCAmelCase__							: str 							=						int(builtins.input()  )
                         except ValueError:
                              UpperCAmelCase__							: List[Any] 							=						default_choice
                    else:
                         UpperCAmelCase__							: Optional[int] 							=						self.handle_input()
                    if choice is not None:
                         reset_cursor()
                         for _ in range(len(self.choices  ) + 1  ):
                              move_cursor(1 ,			"UP"  )
                              clear_line()
                         self.write_choice(__UpperCamelCase ,			"\n"  )
                         return choice





"""simple docstring"""




from timeit import timeit



def 							a__ (				lowerCAmelCase	:       int		):






     '''simple docstring'''
     if number < 0:
          raise ValueError("the value of input must not be negative"		)
     UpperCAmelCase__							: Tuple 							=						0
     while number:
          number &= number - 1
          result += 1
     return result



def 							a__ (				lowerCAmelCase	:       int		):






     '''simple docstring'''
     if number < 0:
          raise ValueError("the value of input must not be negative"		)
     UpperCAmelCase__							: Union[str, Any] 							=						0
     while number:
          if number % 2 == 1:
               result += 1
          number >>= 1
     return result



def 							a__ (				):






     '''simple docstring'''

     def do_benchmark(lowerCAmelCase	:       int		) -> None:
          UpperCAmelCase__							: Dict 							=						"import __main__ as z"
          print(F"Benchmark when {number = }:"		)
          print(F"{get_set_bits_count_using_modulo_operator(lowerCAmelCase		) = }"		)
          UpperCAmelCase__							: Tuple 							=						timeit("z.get_set_bits_count_using_modulo_operator(25)"       ,    setup=lowerCAmelCase		)
          print(F"timeit() runs in {timing} seconds"		)
          print(F"{get_set_bits_count_using_brian_kernighans_algorithm(lowerCAmelCase		) = }"		)
          UpperCAmelCase__							: Any 							=						timeit(
              "z.get_set_bits_count_using_brian_kernighans_algorithm(25)"       ,    setup=lowerCAmelCase       ,    )
          print(F"timeit() runs in {timing} seconds"		)

     for number in (25, 37, 58, 0):
          do_benchmark(lowerCAmelCase		)
          print()


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    benchmark()



