Created
April 2, 2013 01:49
-
-
Save coyotebush/5289348 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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