language-agnosticcode-golf

Convert decimal number to excel-header-like number


0 = A
1 = B
...
25 = Z
26 = AA
27 = AB
...
701 = ZZ
702 = AAA

I cannot think of any solution that does not involve loop-bruteforce :-(

I expect a function/program, that accepts a decimal number and returns a string as a result.


Solution

  • Haskell, 78 57 50 43 chars

    o=map(['A'..'Z']:)$[]:o
    e=(!!)$o>>=sequence
    

    Other entries aren't counting the driver, which adds another 40 chars:

    main=interact$unlines.map(e.read).lines
    

    A new approach, using a lazy, infinite list, and the power of Monads! And besides, using sequence makes me :), using infinite lists makes me :o