Incrementing alphabets

前端 未结 5 1920
轮回少年
轮回少年 2020-12-19 13:29

I am trying to create a function which will give me alphabet position when an index is passed. It will be same like how excel shows it\'s columns. A...Z, AA,AB.... I wrote t

5条回答
  •  清歌不尽
    2020-12-19 14:03

    I don't want to answer the question in C# but I'm going to show you how easy this is in Haskell.

    alphas :: [String]
    alphas = [x ++ [c] | x <- ([]:alphas), c <- ['A'..'Z']]
    
    Prelude> take 100 alphas
    ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T",
     "U","V","W","X","Y","Z","AA","AB","AC","AD","AE","AF","AG","AH","AI","AJ","AK",
     "AL","AM","AN","AO","AP","AQ","AR","AS","AT","AU","AV","AW","AX","AY","AZ","BA",
     "BB","BC","BD","BE","BF","BG","BH","BI","BJ","BK","BL","BM","BN","BO","BP","BQ",
     "BR","BS","BT","BU","BV","BW","BX","BY","BZ","CA","CB","CC","CD","CE","CF","CG",
     "CH","CI","CJ","CK","CL","CM","CN","CO","CP","CQ","CR","CS","CT","CU","CV"]
    

提交回复
热议问题