2018/Day05/Day5A.hs

23 lines
583 B
Haskell

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