Last active
May 16, 2016 15:03
-
-
Save hmasato/8979ff25e9d2c5d44883 to your computer and use it in GitHub Desktop.
[Python] numToAlphaSeq: int value to str sequence
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
#hmasato | |
#https://gist.github.com/hmasato/8979ff25e9d2c5d44883 | |
def numToAlphaSeq(intValue, upperCase = True, baseStr = 'abcdefghijklmnopqrstuvwxyz'): | |
ret = '' | |
if not str(intValue).isdigit(): return(ret) | |
baseDecimal = len(baseStr) | |
while intValue >= 0: | |
remainder = int(intValue % baseDecimal) #remainder | |
intValue = (intValue - 1 - remainder) / baseDecimal | |
ret = baseStr[remainder] + ret | |
if upperCase: ret = ret.upper() | |
return(ret) | |
""" | |
numToAlphaSeq(0) | |
# Result: A | |
numToAlphaSeq(29) | |
# Result: AD | |
numToAlphaSeq(1150505010) | |
# Result: CRUPVLS | |
numToAlphaSeq(0, upperCase=False) | |
# Result: a | |
numToAlphaSeq(29, upperCase=False) | |
# Result: ad | |
numToAlphaSeq(1150505010, upperCase=False) | |
# Result: crupvls | |
numToAlphaSeq(1150505010, baseStr="ABC") | |
# Result: BBBACAABABABCCAAACA # | |
numToAlphaSeq(1150505010, baseStr="012345") | |
# Result: 154544040520 # | |
numToAlphaSeq(1150505010, baseStr="0123") | |
# Result: 233033133223132 # | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment