- Published on
- Fri Jan 24, 2014
EPI 5.8 - Spreadsheet column encoding
Problem ¶
Write a function that converts excel column IDs to corresponding integers with “A” corresponding to 1 and so on.
Solution ¶
We will modify the solution in EPI 5.6 slightly so that we have:
1indexOf :: Eq a => a -> [a] -> Int
2indexOf item xs
3 | length firstMatched == 0 = -1
4 | otherwise = fst (head firstMatched)
5 where
6 matchesItem x = snd x /= item
7 firstMatched = dropWhile matchesItem
8 (zip [0 .. (length xs) - 1] xs)
9
10
11digitIndices :: [Char] -> [Int]
12digitIndices digits = [ indexOf (chr i) digits | i <- [0 .. 255]]