Day 05.
This commit is contained in:
parent
49f211ca63
commit
ac3bd77f23
|
@ -30,4 +30,4 @@ import qualified Day24
|
|||
import qualified Day25
|
||||
|
||||
main :: IO ()
|
||||
main = Day04.main
|
||||
main = Day05.main
|
||||
|
|
File diff suppressed because one or more lines are too long
13
src/Day05.hs
13
src/Day05.hs
|
@ -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
|
Loading…
Reference in New Issue