Last active
December 2, 2018 14:33
-
-
Save fgaz/71afc92e15ba22cee859ab629d9c9f90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Maybe | |
import Data.List | |
import qualified Data.Set as S | |
import Data.Bifunctor | |
d01_read :: IO [Integer] | |
d01_read = fmap (read . (dropWhile (=='+'))) <$> lines <$> readFile "input" | |
d01_1 :: [Integer] -> Integer | |
d01_1 = sum | |
d01_2 :: [Integer] -> Integer | |
-- please send help | |
d01_2 = fromJust . head . dropWhile isNothing . fmap snd . scanl (\(m,r) n -> if S.member n m then (m, r <|> Just n) else (S.insert n m, r)) (mempty, Nothing) . scanl (+) 0 . cycle | |
d02_read :: IO [String] | |
d02_read = lines <$> readFile "input" | |
d02_1 :: [String] -> Integer | |
d02_1 = uncurry (*) . bimap (length . filter (any ((==2) . length))) (length . filter (any ((==3) . length))) . (\x->(x,x)) . fmap (group . sort) | |
d02_2 :: [String] -> [Char] | |
d02_2 ids = catMaybes $ (\[a,b] -> zipWith (\x y -> if x==y then Just x else Nothing) a b) $ [a|a<-ids,b<-ids,(==1) $ length $ filter id $ zipWith (/=) a b] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment