Guest User

Untitled

a guest
Mar 14th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. -- ColCalc.hs
  2. --
  3. -- Convert integer values to Excel column names
  4. --
  5. -- E.g. 1 -> A, 2 -> B, 27 -> AA, 52 -> AZ etc.
  6. --
  7. module ColCalc (intToCol) where
  8.  
  9. import Data.List
  10. import Data.Char
  11.  
  12. intToCol :: Int -> String
  13. intToCol n = reverse $ unfoldr step n
  14. where step x | x == 0 = Nothing
  15. | otherwise = Just (toAscii (x `mod` 26), (x - 1) `div` 26)
  16. toAscii i = chr $ (if i == 0 then 26 else i) + 64
Add Comment
Please, Sign In to add comment