X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=advent24%2FMain.hs;h=e1836b22ca9cdf012344a6c3e60bd730d22c17d1;hb=1ab3e062eb1b3b28a8aead9834afc962ca142451;hp=2b85e46eebd9172b6f7d9d94c4b9e265d86e8a4b;hpb=8f8a643512f241b116b6da3cc43d2a9cd7360a42;p=advent-of-code-21.git diff --git a/advent24/Main.hs b/advent24/Main.hs index 2b85e46..e1836b2 100644 --- a/advent24/Main.hs +++ b/advent24/Main.hs @@ -1,15 +1,15 @@ --- Writeup at https://work.njae.me.uk/2021/12/29/advent-of-code-2021-day-24/ +-- Writeup at https://work.njae.me.uk/2022/04/23/advent-of-code-2021-day-24/ -- Based on ideas by Daniel Lin, -- taken from https://github.com/ephemient/aoc2021/blob/main/hs/src/Day24.hs -import Debug.Trace +-- import Debug.Trace import Data.Text (Text) import qualified Data.Text.IO as TIO import Data.Attoparsec.Text -- hiding (take, takeWhile) import Control.Applicative -import qualified Data.Map as M -import Data.Map ((!)) +import qualified Data.Map.Strict as M +import Data.Map.Strict ((!)) import Data.List import Control.Monad import Data.Maybe @@ -217,10 +217,10 @@ eqlP = Eql <$> ("eql " *> registerP) <*> (" " *> argumentP) registerP, wP, xP, yP, zP :: Parser Register registerP = choice [wP, xP, yP, zP] -wP = "w" *> pure W -xP = "x" *> pure X -yP = "y" *> pure Y -zP = "z" *> pure Z +wP = W <$ "w" +xP = X <$ "x" +yP = Y <$ "y" +zP = Z <$ "z" argumentP :: Parser Argument argumentP = (Reg <$> registerP) <|> (Lit <$> signed decimal)