summaryrefslogtreecommitdiff
path: root/2020/6.hs
blob: 14aa44ac94b0a69b9868d3c1ee52e20dcc667d78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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))