AoC2018/Day5/Part1.hs

22 lines
643 B
Haskell
Executable File

#! /usr/bin/env stack
-- stack --resolver lts-12.20 --install-ghc script
{-# LANGUAGE FlexibleContexts, LambdaCase #-}
module Main where
import Data.Function (fix)
import qualified Data.Char as C
import qualified Data.List as L
main :: IO ()
main = interact $ show . react . takeWhile C.isAlpha
react input =
let scan (x:y:zs) = if x `reactsWith` y then scan zs else (x : scan (y:zs))
scan zs = zs
input' = scan input
result = (input', length input')
in if input' == input then result else react input'
x `reactsWith` y = (C.isUpper x && C.toLower x == y) ||
(C.isLower x && C.toUpper x == y)