Puzzler: Converting numbers

Bernhard Strohmeier:

I tried

(0 0 1 + 26 26 26 #: 676) { alpha

a a

I thought about this last night, after I'd posted. Sorry I didn't

think of it before.

The problem, essentially, is that most of the time you want base 26,

however the first time you run into a digit, you want base 27.

A-Z constitutes one (base 26) range

AA-ZZ constitutes another (base 26) range

AAA-ZZZ constitutes third (base 26) range,

etc.

These correspond to the decimal numeric ranges:

1-26, 27-702, 703-18278, etc.

However, technically, 0 can be considered part of that first range, so

it's 0-26. [In all the other ranges, the number which would

correspond to zero falls in the previous range.]

An expression bounding each of these ranges at the low end would be:

lowbound =. (}: |. +/\ 26 ^ i. 8), 0

or

lowbound=. 8353082582 321272406 12356630 475254 18278 702 26 0

[Note, the 8 is an explicit encoding of the idea that 8 digits is

adequate for expressing any 32 bit integer. You can change it to suit

your taste.]

Given this definition of these ranges, the result you're looking for is:

alpha=. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ '

alpha {~ 27 | (26 * n </ lowbound) + ((#lowbound)#26) #: n

You can simplify slightly to:

alpha {~ (- n </ lowbound) + ((#lowbound)#26) #: n

--

Raul