Created
February 3, 2015 10:40
-
-
Save drj11/2577a9a0262f1a9bc016 to your computer and use it in GitHub Desktop.
Wrong code for converting number to Excel row ref
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
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