Skip to content

Instantly share code, notes, and snippets.

@SamadiPour
Last active April 18, 2020 13:52
Show Gist options
  • Save SamadiPour/addb08f0e00eb0a7f695e06c814ee258 to your computer and use it in GitHub Desktop.
Save SamadiPour/addb08f0e00eb0a7f695e06c814ee258 to your computer and use it in GitHub Desktop.
Compare str_convert and split with divide
import cProfile
# https://quera.ir/problemset/contest/3539/%D8%B3%D8%A4%D8%A7%D9%84-%D8%AA%DA%A9%D8%B1%D9%82%D9%85%DB%8C
def convert_to_string(number: int):
for i in range(10_000_000): # loop 10_000_000 times
array = list(str(number))
# number_sum = 0
while len(array) != 1:
number_sum = 0
for j in range(len(array)):
number_sum = number_sum + int(array[j])
array = list(str(number_sum))
# print(number_sum)
def divide(number_origin: int):
for i in range(10_000_000): # loop 10_000_000 times
number = number_origin # get original number from input
number_sum = number
while number_sum >= 10:
number = number_sum
number_sum = 0
while number >= 10:
number_sum += number % 10
number = number // 10
number_sum += number % 10
def divide_two(number_origin: int):
for i in range(10_000_000): # loop 10_000_000 times
number = number_origin # get original number from input
while number >= 10:
temp = number % 10
number = (number // 10) + temp
if __name__ == '__main__':
cProfile.run('convert_to_string(999999999999999999)')
cProfile.run('divide(999999999999999999)')
cProfile.run('divide_two(999999999999999999)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment