Re: Strange 26base enumeration
- To: mathgroup at smc.vnet.net
- Subject: [mg111203] Re: Strange 26base enumeration
- From: Christopher Henrich <chenrich at monmouth.com>
- Date: Fri, 23 Jul 2010 07:13:30 -0400 (EDT)
- References: <i293lk$m1e$1@smc.vnet.net>
In article <i293lk$m1e$1 at smc.vnet.net>,
"Dr Bruno Campanini" <cmpbrn at gmail.com> wrote:
> I need an algorithm to get such a table:
>
> A
> B
> .
> .
> Z
> AA
> AB
> .
> .
> AZ
> BA
> BB
> .
> .
> BZ
> CA
> .
> .
> ZA
> ZB
> .
> .
> ZZ
> AAA
> AAB
> .
> .
> AAZ
> ABA
> .
> .
> ABZ
> .
> AZA
> .
> AZZ
> BAA
> .
> ZZZ
> AAAA
> AAAB
> .
> .
> ZZZZ
> AAAAA
> AAAAB
> .
>
> Any idea?
>
> Bruno
Here's some code, which can probably be made more elegant. (I translated
it from C++ code.) It assumes that the input is a non-negative integer.
AlphaCode[nn_] := Module[{n, result, next},
n = nn + 1;
result = "";
While[n > 0,
n = n - 1;
next = FromCharacterCode[Mod[n, 26] + ToCharacterCode["A"]];
result = next <> result;
n = Quotient[n, 26]];
result];
--
Christopher J. Henrich
chenrich at monmouth.com
http://www.mathinteract.com
"A bad analogy is like a leaky screwdriver." -- Boon