aoc2020/day6.hs

23 lines
596 B
Haskell
Raw Permalink Normal View History

2020-12-06 02:44:58 -05:00
import Data.List (nub)
2020-12-06 01:53:39 -05:00
main :: IO ()
main = do
raw <- readFile "day6.txt"
let ls = map concat $ split "" $ lines raw
ms = split "" $ lines raw
ansA = sum $ map (length . nub) ls
ansB = sum $ map (length . (foldr match ['a'..'z'])) ms
in do
putStrLn $ "day6a: " ++ (show ansA)
putStrLn $ "day6b: " ++ (show ansB)
2020-12-06 02:44:58 -05:00
match :: Ord a => [a] -> [a] -> [a]
match as bs = nub $ filter (`elem` bs) as
2020-12-06 01:53:39 -05:00
split :: Eq a => a -> [a] -> [[a]]
split _ [] = []
2020-12-06 02:03:46 -05:00
split d as = chunk : (split d rest)
where
chunk = takeWhile (/= d) as
rest = drop 1 $ dropWhile (/= d) as