a guest Mar 14th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- -- ColCalc.hs
- -- Convert integer values to Excel column names
- -- E.g. 1 -> A, 2 -> B, 27 -> AA, 52 -> AZ etc.
- module ColCalc (intToCol) where
- import Data.List
- import Data.Char
- intToCol :: Int -> String
- intToCol n = reverse $ unfoldr step n
- where step x | x == 0 = Nothing
- | otherwise = Just (toAscii (x `mod` 26), (x - 1) `div` 26)
- toAscii i = chr $ (if i == 0 then 26 else i) + 64
RAW Paste Data