Programming Riddle: How might you translate an Excel column name to a number?

前端 未结 28 1411
[愿得一人]
[愿得一人] 2020-11-29 22:26

I was recently asked in a job interview to resolve a programming puzzle that I thought it would be interesting to share. It\'s about translating Excel column letters to actu

28条回答
  •  伪装坚强ぢ
    2020-11-29 22:59

    I wrote this ages ago for some Python script:

    def index_to_int(index):
        s = 0
        pow = 1
        for letter in index[::-1]:
            d = int(letter,36) - 9
            s += pow * d
            pow *= 26
        # excel starts column numeration from 1
        return s
    

提交回复
热议问题