Skip to content

Instantly share code, notes, and snippets.

@yatt
Created October 25, 2011 15:55
Show Gist options
  • Select an option

  • Save yatt/1313242 to your computer and use it in GitHub Desktop.

Select an option

Save yatt/1313242 to your computer and use it in GitHub Desktop.
toy
# 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