Files
advent-of-code-2023/day19/Part1.hs
2023-12-19 13:35:45 +01:00

22 lines
831 B
Haskell

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