Haskell:
module Main where import Control.Arrow (Arrow((&&&))) import Data.List.Split (splitOn) import Control.Monad (join) import Data.List (nub, intersect) parseInput :: String -> [[String]] parseInput = fmap lines . splitOn "\n\n" solveP1 :: [[String]] -> Int solveP1 = sum . fmap (length . nub . join) solveP2 :: [[String]] -> Int solveP2 = sum . fmap answers where answers [x] = length x answers (x:xs) = length . foldr intersect x $ xs main :: IO () main = print . (solveP1 &&& solveP2) . parseInput =<< readFile "./day6inp.txt"
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Haskell: