Last active
June 17, 2016 21:16
-
-
Save oprypin/0ccd155c5ab4be890f239eed92a3e145 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def succ(s): | |
a = list(s) | |
for i in reversed(range(len(a))): | |
a[i] = chr(ord(a[i]) + 1) | |
if a[i] <= 'z': | |
break | |
a[i] = 'a' | |
else: | |
a.insert(0, 'a') | |
return ''.join(a) | |
succ('aaa') # 'aab' | |
succ('a') # 'b' | |
succ('xyz') # 'xza' | |
succ('zzz') # 'aaaa' | |
succ('ayx') # 'ayy' | |
succ('lman') # 'lmao' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment