Skip to content

Instantly share code, notes, and snippets.

@coci
Last active April 27, 2020 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coci/d92113cf483afd005c639feefa95de1c to your computer and use it in GitHub Desktop.
Save coci/d92113cf483afd005c639feefa95de1c to your computer and use it in GitHub Desktop.
import math
def reverse_int_without_string(number):
"""
reverse without change number into string
"""
number_copy = abs(number)
digits_number = [] # split number by their digits
while number_copy > 0 :
digits_number.append(number_copy%10)
number_copy = number_copy // 10
# multiple number with her index with 10 = > 123 => 1*100 + 2* 10 + 3 * 1
number_copy = []
for i in digits_number :
digits_number = digits_number[1:]
for j in range(len(digits_number)):
print(j)
i *= 10
number_copy.append(i)
number_copy = sum(number_copy)
return int(math.copysign(number_copy,number)*-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment