summaryrefslogtreecommitdiff
path: root/2020/6.hs
diff options
context:
space:
mode:
Diffstat (limited to '2020/6.hs')
-rw-r--r--2020/6.hs21
1 files changed, 21 insertions, 0 deletions
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))