1
0
Fork 0
This commit is contained in:
Jonathan Chan 2018-12-05 11:53:46 -08:00
parent 49f211ca63
commit ac3bd77f23
3 changed files with 14 additions and 2 deletions

View File

@ -30,4 +30,4 @@ import qualified Day24
import qualified Day25
main :: IO ()
main = Day04.main
main = Day05.main

1
input/05.txt Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,17 @@
module Day05 (main) where
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']
main :: IO ()
main = do
input <- readFile "input/05.txt"
print input
print $ part1 input
print $ part2 input