Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/python
def incnums(mx, amt, nums):
if len(nums) == 0:
nums.append(-1)
(q, r) = divmod(nums[-1] + amt, mx + 1)
nums.pop()
if q > 0:
incnums(mx, q, nums)
nums.append(r)
def add_inputbase(s, amt):
mn = 32
mx = 126
nums = map(lambda x: ord(x) - mn, s)
incnums(mx - mn, amt, nums)
return ''.join(map(lambda x: chr(x + mn), nums))
def test_add_inputbase():
print add_inputbase('a', 3) == 'd'
print add_inputbase('glhf', 3) == 'glhi'
print add_inputbase('glhf', 24) == 'glh~'
print add_inputbase('glhf', 25) == 'gli '
print add_inputbase('~~~~', 1) == ' '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment