Skip to content

Instantly share code, notes, and snippets.

@zhangyangjing
Last active August 29, 2015 14:03
Show Gist options
  • Save zhangyangjing/25840008470de6704752 to your computer and use it in GitHub Desktop.
Save zhangyangjing/25840008470de6704752 to your computer and use it in GitHub Desktop.
dtd
#!/usr/bin/python
# -*- coding: utf-8 -*-
dt = ['3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y']
td = {
'3': 0, '4': 1, '5': 2, '6': 3, '7': 4, '8': 5, '9': 6, 'A': 7, 'B': 8,
'C': 9, 'D': 10, 'E': 11, 'F': 12, 'G': 13, 'H': 14, 'J': 15, 'K': 16,
'L': 17, 'M': 18, 'N': 19, 'P': 20, 'Q': 21, 'R': 22, 'S': 23, 'T': 24,
'U': 25, 'V': 26, 'W': 27, 'X': 28, 'Y': 29}
def d2t(v):
t = ''
while True:
v, mod = divmod(v, 30)
t = dt[mod] + t
if 0 == v:
return t
def t2d(v):
d = 0
v = v[::-1]
for i in range(0, len(v)):
d += td[v[i]] * pow(30, i)
return d
# TEST
t = 'ABCD'
print t
d = t2d(t)
print d
t = d2t(d)
print t
print t2d('3333')
print t2d('YYYY')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment