0

Does any one have algorithm or logic to Convert A to 1 ,B to 2, ... ,Z to 26 and then ,AA to 27, AB to 28 and so on BUT BA or cb or cbe or any string which has letters in descending order should not be numbered a for eg: BB should be 53 as BA is not numbered .this question is very similar to Convert A to 1 B to 2 ... Z to 26 and then AA to 27 AB to 28 (column indexes to column references in Excel) but with a slight difference as mentioned above

Community
  • 1
  • 1

2 Answers2

0

Assume your first character in cell A1 and second character in cell B1, the following formula should help you to calculate the value

=IF(ISBLANK(A1),0,CODE(A1)-CODE("A")+1)*26+(CODE(B1)-CODE("A")+1)

For only A to Z, A1 is blank and put the single character in B1.

Ken Cheung
  • 1,778
  • 14
  • 13
0

I assume you want to have limited amount of mappings

  1. Generate all mapping you want in order you need

    A, B, C, ... , Z, AA, AB, ... ,AZ, BA, BB, ..., BZ

  2. Filter mappings with letters in non-descending order

    A, B, C, ... , AA, AB, ... ,AZ, BB, ..., BZ (BA disappeared!)

    To check if the string is in non-descending order, just compare it to its sorted version.

  3. Enumerate!

mishadoff
  • 10,719
  • 2
  • 33
  • 55