From 3b5efe46256a545f2e258003cf11c9c6ef6dcb7f Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 6 Dec 2020 10:41:16 +0530 Subject: ad initial solution to day06 --- execs/Day06.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 execs/Day06.hs (limited to 'execs') diff --git a/execs/Day06.hs b/execs/Day06.hs new file mode 100644 index 0000000..c35fd21 --- /dev/null +++ b/execs/Day06.hs @@ -0,0 +1,19 @@ + +module Main where + +import Data.Char (digitToInt) +import Data.List (sort) +import Data.Set (Set) +import qualified Data.Set as Set +import Control.Monad + +parseLines :: [String] -> [String] +parseLines allLines = unwords first : next + where (first, rest) = break null allLines + next = if null rest then [] else parseLines (tail rest) + +main :: IO () +main = do + n <- parseLines . lines <$> readFile "input/06" + print $ sum $ map (Set.size . Set.fromList . filter (/= ' ')) n + print $ sum $ map (Set.size . foldl1 Set.intersection . map Set.fromList . words) n -- cgit v1.2.3