Last active
December 14, 2015 16:59
-
-
Save munhitsu/5118993 to your computer and use it in GitHub Desktop.
slightly crazy universal base encoder (number to alphabet)
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
BASE_ALPHABET = "123456789abcdefghijkmnopqrstuvwxyz" | |
def encode_base_x(n): | |
base = len(BASE_ALPHABET) | |
def chars(num): | |
while num >= base: | |
num, mod = divmod(num, base) | |
yield BASE_ALPHABET[mod] | |
yield BASE_ALPHABET[num] | |
return "".join(chars(n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment