From: Neil Smith Date: Tue, 14 Jun 2022 13:53:39 +0000 (+0100) Subject: Tweaked some parsing code X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=1ab3e062eb1b3b28a8aead9834afc962ca142451;p=advent-of-code-21.git Tweaked some parsing code --- diff --git a/advent21/Main.hs b/advent21/Main.hs index 01d23e7..3048daf 100644 --- a/advent21/Main.hs +++ b/advent21/Main.hs @@ -113,7 +113,7 @@ mod1 a b = ((a - 1) `mod` b) + 1 -- Parsing -playerP = ("1" *> pure Player1) <|> ("2" *> pure Player2) +playerP = (Player1 <$ "1") <|> (Player2 <$ "2") playerStateP = playerify <$> ("Player " *> playerP) <*> (" starting position: " *> decimal) where playerify name pos = (name, PlayerState {position = pos, score = 0}) diff --git a/advent22/Main.hs b/advent22/Main.hs index dc67b3f..ca6bddd 100644 --- a/advent22/Main.hs +++ b/advent22/Main.hs @@ -99,7 +99,8 @@ cuboidP = cubify <$> (partiyP <* " ") <*> (boundsP `sepBy` ",") } vecify [c1, c2, c3] = V3 c1 c2 c3 -partiyP = ("on" *> pure On) <|> ("off" *> pure Off) +-- partiyP = ("on" *> pure On) <|> ("off" *> pure Off) +partiyP = (On <$ "on") <|> (Off <$ "off") boundsP = (,) <$> (("x" <|> "y" <|> "z") *> "=" *> signed decimal) <*> (".." *> signed decimal) diff --git a/advent24/Main.hs b/advent24/Main.hs index ae03fac..e1836b2 100644 --- a/advent24/Main.hs +++ b/advent24/Main.hs @@ -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)