Advent of Code solutions https://adventofcode.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

15 lines
506 B

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)