Given a table with position - 2 character combination pairs like this:
1. aa
2. ab
3. ac
4. ad
...
27. ba
28. bb
29. bc
30. bd
Assuming there are unique combinations with two characters from the alphabet following the same pattern.
How do I calculate what is the first and second character of the combination, if I know the position. That is, how do I find position 28 holds bb?
EDIT:
The answer that also describes how to do the reverse, i.e find the position of a combination based on the pair is going to be the most useful answer.
Assuming you have an alphabet
A = ['a','b',...'z']and a permutation listL = ['aa', 'ab', ..., 'az', 'ba', ... , 'zz'], with the first index starting from 1. (BTW the arithmetic would be much cleaner if you start indexing from $0$, like in the C language, for example.)Then, the permutations come in groups of $26$, so if you are given an index $k$, then
If you were to number starting with $0$, the formulae become
Another free update you get with C, for example, is that if you declare
int k, d = 26;thenk/dcomputes $\lfloor k/d \rfloor$ automatically, no extra flooring is needed.UPDATE
The inversion is simple. If first letter has index $F$ and last has index $L$, the offset is given by