Day 19
This commit is contained in:
21
day19/Part1.hs
Normal file
21
day19/Part1.hs
Normal 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
|
||||
Reference in New Issue
Block a user