diff options
author | tomsmeding <tom.smeding@gmail.com> | 2016-12-14 20:19:02 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2016-12-14 20:19:02 +0100 |
commit | 2d02f553aa4cc4ded630628eccdf34f55937cee5 (patch) | |
tree | d5377ebdff68788725b5820d5331ce7b6c9d4a84 /2015/day16.hs | |
parent | 97b4c5d86cc12447ac6845e25a863e26a88aec35 (diff) |
Add 2015 sources
Diffstat (limited to '2015/day16.hs')
-rw-r--r-- | 2015/day16.hs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/2015/day16.hs b/2015/day16.hs new file mode 100644 index 0000000..a18fce1 --- /dev/null +++ b/2015/day16.hs @@ -0,0 +1,36 @@ +import Data.Char +import Data.List +import Control.Monad +import qualified Data.Map.Strict as Map +import Data.Map.Strict ((!)) + +realSue :: Map.Map String (Int -> Bool) +realSue = Map.fromList [ -- for part 1, make all functions equalities + ("children", (==3)), + ("cats", (>7)), + ("samoyeds", (==2)), + ("pomeranians",(<3)), + ("akitas", (==0)), + ("vizslas", (==0)), + ("goldfish", (<5)), + ("trees", (>3)), + ("cars", (==2)), + ("perfumes", (==1))] + +parse :: String -> [(String,Int)] +parse s = parse' $ drop 2 $ words s + +parse' :: [String] -> [(String,Int)] +parse' [] = [] +parse' (k:v:xs) = (init k,read $ takeWhile isDigit v) : parse' xs + +matches :: [(String,Int)] -> Map.Map String (Int -> Bool) -> Bool +matches [] _ = True +matches ((k,v):atts) map = (map ! k) v && matches atts map + +day16 :: IO () +day16 = do + input <- liftM (zip [1..] . map parse . lines) $ readFile "day16.txt" + sequence_ $ map (print . fst) $ filter (\(i,atts) -> matches atts realSue) input + +main = day16 |