






'''simple docstring'''

def     __lowercase  (_lowercase     )   ->     Optional[int]:


     """simple docstring"""

     if not isinstance(a_,						a_     ):
          raise ValueError("""multiplicative_persistence() only accepts integral values"""     )
     if num < 0:
          raise ValueError("""multiplicative_persistence() does not accept negative values"""     )

     __lowerCamelCase						:       Optional[Any]				   =				0
     __lowerCamelCase						:       Tuple				   =				str(a_     )

     while len(a_     ) != 1:
          __lowerCamelCase						:       Dict				   =				[int(a_     ) for i in num_string]

          __lowerCamelCase						:       Union[str, Any]				   =				1
          for i in range(0,						len(a_     )     ):
               total *= numbers[i]

          __lowerCamelCase						:       Union[str, Any]				   =				str(a_     )

          steps += 1
     return steps
def     __lowercase  (_lowercase     )   ->     str:


     """simple docstring"""

     if not isinstance(a_,						a_     ):
          raise ValueError("""additive_persistence() only accepts integral values"""     )
     if num < 0:
          raise ValueError("""additive_persistence() does not accept negative values"""     )

     __lowerCamelCase						:       Dict				   =				0
     __lowerCamelCase						:       str				   =				str(a_     )

     while len(a_     ) != 1:
          __lowerCamelCase						:       int				   =				[int(a_     ) for i in num_string]

          __lowerCamelCase						:       List[Any]				   =				0
          for i in range(0,						len(a_     )     ):
               total += numbers[i]

          __lowerCamelCase						:       Union[str, Any]				   =				str(a_     )

          steps += 1
     return steps


if __name__ == "__main__":
    import doctest

    doctest.testmod()











'''simple docstring'''

UpperCAmelCase__						:List[Any]          =			256
# Modulus to hash a string
UpperCAmelCase__						:str          =			1_000_003
def     __lowercase  (_lowercase,						_lowercase     )   ->     bool:


     """simple docstring"""
     __lowerCamelCase						:       str				   =				len(_lowercase     )
     __lowerCamelCase						:       List[str]				   =				len(_lowercase     )
     if p_len > t_len:
          return False

     __lowerCamelCase						:       Optional[Any]				   =				0
     __lowerCamelCase						:       Tuple				   =				0
     __lowerCamelCase						:       Dict				   =				1

     # Calculating the hash of pattern and substring of text
     for i in range(_lowercase     ):
          __lowerCamelCase						:       Optional[int]				   =				(ord(pattern[i]     ) + p_hash * alphabet_size) % modulus
          __lowerCamelCase						:       Dict				   =				(ord(text[i]     ) + text_hash * alphabet_size) % modulus
          if i == p_len - 1:
               continue
          __lowerCamelCase						:       Dict				   =				(modulus_power * alphabet_size) % modulus

     for i in range(0,						t_len - p_len + 1     ):
          if text_hash == p_hash and text[i : i + p_len] == pattern:
               return True
          if i == t_len - p_len:
               continue
          # Calculate the https://en.wikipedia.org/wiki/Rolling_hash
          __lowerCamelCase						:       Dict				   =				(
              (text_hash - ord(text[i]     ) * modulus_power) * alphabet_size
              + ord(text[i + p_len]     )
          ) % modulus
     return False
def     __lowercase  ()   ->     None:


     """simple docstring"""
     __lowerCamelCase						:       List[Any]				   =				"""abc1abc12"""
     __lowerCamelCase						:       Optional[Any]				   =				"""alskfjaldsabc1abc1abc12k23adsfabcabc"""
     __lowerCamelCase						:       List[Any]				   =				"""alskfjaldsk23adsfabcabc"""
     assert rabin_karp(_lowercase,						_lowercase     ) and not rabin_karp(_lowercase,						_lowercase     )

     # Test 2)
     __lowerCamelCase						:       Optional[int]				   =				"""ABABX"""
     __lowerCamelCase						:       Dict				   =				"""ABABZABABYABABX"""
     assert rabin_karp(_lowercase,						_lowercase     )

     # Test 3)
     __lowerCamelCase						:       Any				   =				"""AAAB"""
     __lowerCamelCase						:       int				   =				"""ABAAAAAB"""
     assert rabin_karp(_lowercase,						_lowercase     )

     # Test 4)
     __lowerCamelCase						:       Any				   =				"""abcdabcy"""
     __lowerCamelCase						:       Dict				   =				"""abcxabcdabxabcdabcdabcy"""
     assert rabin_karp(_lowercase,						_lowercase     )

     # Test 5)
     __lowerCamelCase						:       str				   =				"""Lü"""
     __lowerCamelCase						:       str				   =				"""Lüsai"""
     assert rabin_karp(_lowercase,						_lowercase     )
     __lowerCamelCase						:       Tuple				   =				"""Lue"""
     assert not rabin_karp(_lowercase,						_lowercase     )
     print("""Success."""     )


if __name__ == "__main__":
   test_rabin_karp()



