Skip to content

Instantly share code, notes, and snippets.

@joncle
Created September 23, 2014 16:02
Show Gist options
  • Save joncle/6b8175ea6f34489d4187 to your computer and use it in GitHub Desktop.
Save joncle/6b8175ea6f34489d4187 to your computer and use it in GitHub Desktop.
def num_to_base(num, base='ab'):
if num == 0:
return base[0]
res = []
while num:
num, m = divmod(num, len(base))
res.append(base[m])
return ''.join(res)
for i in xrange(5):
print num_to_base(i),
# a b ab bb aab
print
for i in xrange(4, 10):
print num_to_base(i),
# aab bab abb bbb aaab baab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment