I decided to do this year in Haskell. Perhaps if it gets too crazy, I'll revert to what I know better, but until now it's been fun.
I might start a library with the groups and addAll functions, seems I'm going to use them for every puzzle...
groups
addAll
import Data.List.Split ( splitOn ) import Data.List ( intersect, nub ) main :: IO () main = do input <- readFile "input" putStrLn "day6" print $ solve1 input print $ solve2 input solve1 :: String -> Int solve1 a = let grouped = groups a answers = map (filter (\x -> x `elem` ['a'..'z']) . nub) grouped in addAll answers solve2 :: String -> Int solve2 a = let grouped = map lines $ groups a intersected = map (foldr1 intersect) grouped in addAll intersected addAll :: [[a]] -> Int addAll = sum . map length groups :: String -> [String] groups = splitOn "\n\n"
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.
I decided to do this year in Haskell. Perhaps if it gets too crazy, I'll revert to what I know better, but until now it's been fun.
I might start a library with the
groups
andaddAll
functions, seems I'm going to use them for every puzzle...