1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
506 B
Haskell

import Bag
import Data.Bifunctor
import Data.List
main :: IO ()
main = do
input <- readFile "input"
putStrLn . show . length . willContain "shiny gold" . map bagSpec . lines $ input
willContain :: String -> [Bag] -> [String]
willContain target bags = foldr union current . map (flip willContain $ bags) $ current
where current = findWithContent target bags
findWithContent :: String -> [Bag] -> [String]
findWithContent target = map fst . filter (elem target . snd) . map (second $ map fst)