Generate excel column name from index
Excel Formula:), 36 chars
=SUBSTITUTE(ADDRESS(1,A1,4),"1","")
Usage:
Sorry, couldn't resist ...
Perl, 17 characters
say[A..XFD]->[<>]
The ..
operator does the same thing as the magical auto-increment, but without the need for the temporary variable and loop. Unless strict subs
is in scope, the barewords A
and XFD
are interpreted as strings.
(This answer was suggested by an anonymous user as an edit to an existing answer. I felt it deserves to be a separate answer, and have made it one. Since it wouldn't be fair for me to gain rep from it, I've made it Community Wiki.)
C, 53 characters
It's like playing golf with a hammer...
char b[4],*p=b+3;f(i){i<0||(*--p=i%26+65,f(i/26-1));}
Normal version:
char b[4];
char *p = b+3;
void f(int i) {
if (i >= 0) {
--p;
*p = i%26 + 65;
f(i/26-1);
}
}
And the usage is like that:
int main(int argc, char *argv[])
{
f(atoi(argv[1]));
printf("%s\n", p);
return 0;
}