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.
 
 
 

13 lines
406 B

import Bag
main :: IO ()
main = do
input <- readFile "input"
putStrLn . show . bagsNeeded "shiny gold" . map bagSpec . lines $ input
bagsNeeded :: String -> [Bag] -> Int
bagsNeeded bagType bags = bagsNeededRec bags (bagType, 1) - 1
bagsNeededRec :: [Bag] -> (String, Int) -> Int
bagsNeededRec bags (bagType, qty) = qty + qty * sum
(maybe [] (map $ bagsNeededRec bags) $ lookup bagType bags)