AoC/2020/day02/day02.hs
2020-12-02 06:51:03 +01:00

26 lines
695 B
Haskell

import Control.Arrow
import Control.Monad
import Data.List.Split
main :: IO ()
main = do
input <- lines <$> readFile "input"
print $ day2a input
print $ day2b input
predicate :: String -> Bool
predicate line = (l>=a) && (l<=b)
where c = head $ words p !! 1
[a,b] = map read $ splitOn "-" $ head $ words p
l = length $ filter (==c) str
[p,str] = splitOn ": " line
day2a = length . filter predicate
day2b = length . filter predicate2
predicate2 :: String -> Bool
predicate2 line = (str!!a==c) /= (str!!b==c)
where c = head $ words p !! 1
[a,b] = map (subtract 1 . read) $ splitOn "-" $ head $ words p
[p,str] = splitOn ": " line