From 5d79edcdbddbd55f3d7130811581233a295726ea Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 6 Dec 2020 20:42:11 +0100 Subject: Day 6 --- 2020/6.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 2020/6.hs (limited to '2020/6.hs') diff --git a/2020/6.hs b/2020/6.hs new file mode 100644 index 0000000..14aa44a --- /dev/null +++ b/2020/6.hs @@ -0,0 +1,21 @@ +module Main (main) where + +import qualified Data.List.NonEmpty as NE +import Data.List.NonEmpty (NonEmpty(..), (<|)) +import qualified Data.Set as Set + +import Input + + +splitOn :: (a -> Bool) -> [a] -> NonEmpty [a] +splitOn _ [] = [] :| [] +splitOn f (x:xs) | f x = [] <| splitOn f xs + | otherwise = let l :| ls = splitOn f xs + in (x : l) :| ls + +main :: IO () +main = do + input <- getInput 6 + let groups = map (map Set.fromList) (NE.toList (splitOn null input)) + print (sum (map (Set.size . Set.unions) groups)) + print (sum (map (Set.size . foldl1 Set.intersection) groups)) -- cgit v1.2.3-54-g00ecf