diff options
author | Julien Dessaux | 2023-05-05 23:01:55 +0200 |
---|---|---|
committer | Julien Dessaux | 2023-05-05 23:01:55 +0200 |
commit | dc4363d9e76ed9815883eea50e1c969213f4c4a3 (patch) | |
tree | ce0cff3a5ff900cb31fe6c35ee56ae8cfef2f175 /2020/19-Monster_Messages | |
parent | 2020-19 part 2 in haskell (diff) | |
download | advent-of-code-dc4363d9e76ed9815883eea50e1c969213f4c4a3.tar.gz advent-of-code-dc4363d9e76ed9815883eea50e1c969213f4c4a3.tar.bz2 advent-of-code-dc4363d9e76ed9815883eea50e1c969213f4c4a3.zip |
patched 2020-19 in haskell
Diffstat (limited to '2020/19-Monster_Messages')
-rw-r--r-- | 2020/19-Monster_Messages/first.hs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/2020/19-Monster_Messages/first.hs b/2020/19-Monster_Messages/first.hs index 56a0cbb..84b0aed 100644 --- a/2020/19-Monster_Messages/first.hs +++ b/2020/19-Monster_Messages/first.hs @@ -3,7 +3,6 @@ module Main (main) where import Control.Monad (void, when) import Data.Either import Data.List (foldl') -import Data.Maybe (isJust) import Data.Map qualified as M import Data.Void (Void) import Text.Megaparsec @@ -70,11 +69,12 @@ compute (Input rules messages) = length . filter id $ map isValid messages Just "" -> True otherwise -> False matches :: RuleID -> Message -> Maybe Message + matches _ [] = Nothing matches ruleId msg = case rules M.! ruleId of Left c -> if head msg == c then (Just $ tail msg) else Nothing Right actions -> case map (processAction msg) actions of - Nothing:a:_ -> a - a:_ -> a + Just a:_ -> Just a + Nothing:Just a:_ -> Just a otherwise -> Nothing processAction :: Message -> Action -> Maybe Message processAction msg action = foldl' step (Just msg) action |