day 6 done woooo
This commit is contained in:
parent
1a6d74520d
commit
52f550dc86
25
day6.hs
Normal file
25
day6.hs
Normal file
@ -0,0 +1,25 @@
|
||||
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 v as = split' v as [] []
|
||||
|
||||
split' :: Eq a => a -> [a] -> [a] -> [[a]] -> [[a]]
|
||||
split' _ [] a as = as ++ [a]
|
||||
split' v (b:bs) a as
|
||||
| b == v = split' v bs [] (as ++ [a])
|
||||
| otherwise = split' v bs (a ++ [b]) as
|
Loading…
Reference in New Issue
Block a user