daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Mar 14th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top