23 lines
619 B
Haskell
23 lines
619 B
Haskell
import Data.List (nub, sort)
|
|
|
|
main :: IO ()
|
|
main = do
|
|
raw <- readFile "day6.txt"
|
|
let ls = map concat $ split "" $ lines raw
|
|
ms = split "" $ lines raw
|
|
ansA = sum $ map (length . nub) ls
|
|
ansB = sum $ map (length . (foldr match ['a'..'z'])) ms
|
|
in do
|
|
putStrLn $ "day6a: " ++ (show ansA)
|
|
putStrLn $ "day6b: " ++ (show ansB)
|
|
|
|
match :: (Ord a, Eq a) => [a] -> [a] -> [a]
|
|
match as bs = (sort . nub) $ filter (`elem` bs) as
|
|
|
|
split :: Eq a => a -> [a] -> [[a]]
|
|
split _ [] = []
|
|
split d as = chunk : (split d rest)
|
|
where
|
|
chunk = takeWhile (/= d) as
|
|
rest = drop 1 $ dropWhile (/= d) as
|