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.

14 lines
406 B
Haskell

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)