2018/Day05/Day5A.hs

23 lines
583 B
Haskell
Raw Normal View History

2018-12-05 13:14:47 +00:00
#!/usr/bin/env stack
-- stack --resolver lts-12.5 script
module Day5A where
2018-12-05 22:26:47 +00:00
import Data.Bits (xor)
2018-12-05 13:14:47 +00:00
import Data.Char
import qualified Data.Foldable as F
invertCase :: Char -> Char
2018-12-05 22:26:47 +00:00
invertCase = chr . xor 0x20 . ord
2018-12-05 13:14:47 +00:00
calcLength :: String -> String -> Int
calcLength ys (x:y:xs)
2018-12-05 22:26:47 +00:00
| x == invertCase y = if null ys
then calcLength ys xs
else calcLength (tail ys) (head ys:xs)
2018-12-05 13:14:47 +00:00
| otherwise = calcLength (x:ys) (y:xs)
calcLength ys [x] = calcLength (x:ys) []
calcLength ys [] = length ys
main :: IO ()
main = interact $ show . calcLength "" . filter (/= '\n')