module Part1 where import Data.Map ((!)) import Commons applyRules :: [Rule] -> Part -> String applyRules (h: t) p = if apply h p then destination h else applyRules t p applyWorkflow :: Workflows -> String -> Part -> Bool applyWorkflow workflows wName part = let destination = applyRules (workflows ! wName) part in case destination of "A" -> True "R" -> False _ -> applyWorkflow workflows destination part getAccepted :: Workflows -> [Part] -> [Part] getAccepted workflows = filter $ applyWorkflow workflows "in" getAcceptedSum :: Workflows -> [Part] -> [Int] getAcceptedSum workflows = map (\ p -> xr p + mr p + ar p + sr p) . getAccepted workflows