2018/src/Day05.hs

17 lines
446 B
Haskell
Raw Normal View History

2018-11-26 02:32:15 +00:00
module Day05 (main) where
2018-12-05 19:53:46 +00:00
import Data.Char (toLower)
part1 :: String -> Int
part1 = length . foldr react []
where react c [] = [c]
react c (u:us) = if (c /= u) && (toLower c == toLower u) then us else (c:u:us)
part2 :: String -> Int
part2 str = minimum . map (\c -> part1 . filter ((/= c) . toLower) $ str) $ ['a'..'z']
2018-11-26 02:32:15 +00:00
main :: IO ()
main = do
input <- readFile "input/05.txt"
2018-12-05 19:53:46 +00:00
print $ part1 input
print $ part2 input