Day 02 Solution
This commit is contained in:
parent
779261f107
commit
3a4709d5b2
25
2020/day02/day02.hs
Normal file
25
2020/day02/day02.hs
Normal file
@ -0,0 +1,25 @@
|
||||
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
|
1000
2020/day02/input
Normal file
1000
2020/day02/input
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user