This commit is contained in:
2023-12-19 13:35:45 +01:00
parent 5d826bffff
commit ec2b691e3b
5 changed files with 147 additions and 0 deletions

21
day19/Part1.hs Normal file
View File

@@ -0,0 +1,21 @@
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