-2

Here's a fun brain teaser.

Can you give me a mathematical equation to calculate the column number of a Microsoft Excel column, given the alphabetic column reference? Let X, Y, & Z represent the alphabetic sequence number, relative to the alphabet (A = 1, B = 2, etc.)

I look forward to seeing your answers.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
DubMart
  • 9
  • 1

1 Answers1

4

It's not clear that your question is about the Mathematica software, but just in case, here's a stab at it:

Clear[converter]
converter[s_String] :=
 FromDigits[Characters[s], 26] /. Thread[CharacterRange["A", "Z"] -> Range[26]]

converter["AB"]
(* Out: 28 *)
MarcoB
  • 67,153
  • 18
  • 91
  • 189
  • This is good, but I don't like to see constants computed more than once in a session, so I would write it With[{chrs = CharacterRange["A", "Z"], nChrs = 26}, With[{rules = Thread[chrs -> Range[nChrs]]}, converter[s_String] := FromDigits[Characters[s], nChrs] /. rules]] – m_goldberg Jun 01 '16 at 00:47