Skip to content

Instantly share code, notes, and snippets.

@drj11
Created February 3, 2015 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drj11/2577a9a0262f1a9bc016 to your computer and use it in GitHub Desktop.
Save drj11/2577a9a0262f1a9bc016 to your computer and use it in GitHub Desktop.
Wrong code for converting number to Excel row ref
import string
def base_(x, acc):
if x == 0:
return acc
string.uppercase
q, r = divmod(x, 26)
l = string.uppercase[r]
return base_(q, l + acc)
def base(x):
return base_(x, "")
print(base(0))
print(base(27))
print(base(2**20-1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment