Skip to content

Instantly share code, notes, and snippets.

@nhtzr
Last active March 22, 2019 20:23
Show Gist options
  • Save nhtzr/da1315a26188eacb6b5ce78d34811fa0 to your computer and use it in GitHub Desktop.
Save nhtzr/da1315a26188eacb6b5ce78d34811fa0 to your computer and use it in GitHub Desktop.
from sys import argv
n = argv[1]
co_dividend = 0
dec_expansion = 0
pow_max = len(n) - 2 # Last iteration should be pow == 0, first it should be the highest
for (i,c) in enumerate(n[:-1]): # Ignore last digit
pow_i = pow_max - i
co_dividend += int(c) # Sum of all digits
dec_expansion += co_dividend * (10 ** pow_i) # Our result will be part of this expansion
c = n[-1]
co_dividend += int(c)
carry_over = int(co_dividend / 9)
reminder = int(co_dividend % 9)
result = dec_expansion + carry_over
print(f"res: {result} , reminder: {reminder}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment