Created
October 25, 2011 15:55
-
-
Save yatt/1313242 to your computer and use it in GitHub Desktop.
toy
This file contains hidden or 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
| # https://twitter.com/#!/mnzktw/status/128811724907360256 | |
| def to26(n): return n and (to26(n / 26) if n / 26 > 0 else []) + [n % 26] or [0] | |
| def toA1(n): return ''.join(['ABCDEFGHIJKLMNOPQRSTUVWXYZ'[d if i == len(to26(n - 1)) - 1 else d-1] for i,d in enumerate(to26(n - 1))]) | |
| print map(toA1, [1, 10, 2000, 30000, 500000, 1000000]) # => ['A', 'J', 'BXX', 'ARIV', 'ABKPT', 'BDWGN'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment