Skip to content

Instantly share code, notes, and snippets.

@joxer
Created March 15, 2019 10:48
Show Gist options
  • Save joxer/4dc3e8a835f830a07dbf546ea9760388 to your computer and use it in GitHub Desktop.
Save joxer/4dc3e8a835f830a07dbf546ea9760388 to your computer and use it in GitHub Desktop.
def shift_array(array):
array.insert(0,0)
return array
def unshift_array(array):
array.pop(0)
return array
def increase(input):
if input[0] == 9 :
input = shift_array(input)
idx = len(input)-1
curry = 0
while(idx > -1):
if(idx == len(input)-1):
input[idx] +=1
input[idx] += curry
if(input[idx] > 9):
input[idx] = input[idx] % 10
curry = 1
else:
curry = 0
idx -= 1
if input[0] == 0 :
input = unshift_array(input)
return input
input = [1,9,3,8]
print(increase(input))
input = [1]
print(increase(input))
input = [9]
print(increase(input))
input = [9,9,9]
print(increase(input))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment