


'''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_   :      List[Any]				    =      False
try:
 a_   :      Dict				    =      _is_package_available("google.colab")
except ModuleNotFoundError:
 pass




@input.register
class 	a       :
 def __init__(	self ,			__magic_name__ = None ,			__magic_name__ = []  )   ->							Any:
      _a      =							0
      _a      =							choices
      _a      =							prompt
      if sys.platform == "win32":
           _a      =							'*'
      else:
           _a      =							'➔ '
 def 							__UpperCAmelCase						(	self ,			__magic_name__ ,			__magic_name__ = ""  )   ->							List[str]:
      if sys.platform != "win32":
           writeColor(self.choices[index] ,			32 ,			__magic_name__  )
      else:
           forceWrite(self.choices[index] ,			__magic_name__  )
 def 							__UpperCAmelCase						(	self ,			__magic_name__  )   ->							Any:
      if index == self.position:
           forceWrite(f' {self.arrow_char} '  )
           self.write_choice(__magic_name__  )
      else:
           forceWrite(f'    {self.choices[index]}'  )
      reset_cursor()
 def 							__UpperCAmelCase						(	self ,			__magic_name__ ,			__magic_name__ = 1  )   ->							Optional[Any]:
      _a      =							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(__magic_name__  )
      move_cursor(__magic_name__ ,			direction.name  )
      self.print_choice(self.position  )
 @input.mark(KEYMAP['up']  )
 def 							__UpperCAmelCase						(	self  )   ->							Any:
      self.move_direction(Direction.UP  )
 @input.mark(KEYMAP['down']  )
 def 							__UpperCAmelCase						(	self  )   ->							Any:
      self.move_direction(Direction.DOWN  )
 @input.mark(KEYMAP['newline']  )
 def 							__UpperCAmelCase						(	self  )   ->							Tuple:
      move_cursor(len(self.choices  ) - self.position ,			'DOWN'  )
      return self.position
 @input.mark(KEYMAP['interrupt']  )
 def 							__UpperCAmelCase						(	self  )   ->							int:
      move_cursor(len(self.choices  ) - self.position ,			'DOWN'  )
      raise KeyboardInterrupt
 @input.mark_multiple(*[KEYMAP[str(__magic_name__  )] for number in range(10  )]  )
 def 							__UpperCAmelCase						(	self  )   ->							Union[str, Any]:
      _a      =							int(chr(self.current_selection  )  )
      _a      =							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 ,			__magic_name__  )
           else:
                return
      else:
           return




 def 							__UpperCAmelCase						(	self ,			__magic_name__ = 0  )   ->							Union[str, Any]:
      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'  )
      _a      =							default_choice
      for i in range(len(self.choices  )  ):
           self.print_choice(__magic_name__  )
           forceWrite('\n'  )
      move_cursor(len(self.choices  ) - self.position ,			'UP'  )
      with cursor.hide():
           while True:
                if in_colab:
                     try:
                          _a      =							int(builtins.input()  )
                     except ValueError:
                          _a      =							default_choice
                else:
                     _a      =							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(__magic_name__ ,			'\n'  )
                     return choice





'''simple docstring'''






from timeit import timeit






def 		_A			(lowerCAmelCase__					:int						)				->					int:




     '''simple docstring'''



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






def 		_A			(lowerCAmelCase__					:int						)				->					int:




     '''simple docstring'''



     if number < 0:
          raise ValueError('the value of input must not be negative'						)
     _a      =							0
     while number:
          if number % 2 == 1:
               result += 1
          number >>= 1
     return result






def 		_A			()				->					None:




     '''simple docstring'''



     def do_benchmark(lowerCAmelCase__					:int						) -> None:
          _a      =							'import __main__ as z'
          print(f'Benchmark when {number = }:'						)
          print(f'{get_set_bits_count_using_modulo_operator(lowerCAmelCase__						) = }'						)
          _a      =							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__						) = }'						)
          _a      =							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()

