Advent of Code solutions https://adventofcode.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

28 lines
777 B

import Data.List
main :: IO ()
main = do
input <- readFile "input"
print . sum . map length . groups $ input
-- Collect each group's answers
groups :: String -> [String]
groups = map (foldr1 intersect . lines) . dlfsplit
-- Split a string into a list across all the double newlines in it
dlfsplit :: String -> [String]
dlfsplit str = a : case b of
[] -> []
b -> dlfsplit b
where (a,b) = dlfsplitonce str
-- Split a string into two across the first double newline found
dlfsplitonce :: String -> (String, String)
dlfsplitonce [] = ([], [])
dlfsplitonce (ca:cb:rest)
| ca == '\n' && cb == '\n' = ([], rest)
| otherwise = (ca:before, after)
where (before, after) = dlfsplitonce (cb : rest)
dlfsplitonce c = (c, [])