aboutsummaryrefslogtreecommitdiff
path: root/2020/02-Password_Philosophy
diff options
context:
space:
mode:
authorJulien Dessaux2023-03-09 23:14:48 +0100
committerJulien Dessaux2023-03-09 23:14:48 +0100
commit8bc73de30d4d9e1d2dd7916b95b2dcd4fc5cab89 (patch)
treefa6d3817e22049d019f6c047c1befaac94cabc0e /2020/02-Password_Philosophy
parentRenamed folder (diff)
downloadadvent-of-code-8bc73de30d4d9e1d2dd7916b95b2dcd4fc5cab89.tar.gz
advent-of-code-8bc73de30d4d9e1d2dd7916b95b2dcd4fc5cab89.tar.bz2
advent-of-code-8bc73de30d4d9e1d2dd7916b95b2dcd4fc5cab89.zip
Improve parsers of 2020-02
Diffstat (limited to '')
-rw-r--r--2020/02-Password_Philosophy/first.hs7
-rw-r--r--2020/02-Password_Philosophy/second.hs7
2 files changed, 4 insertions, 10 deletions
diff --git a/2020/02-Password_Philosophy/first.hs b/2020/02-Password_Philosophy/first.hs
index 85c092e..4fd60b5 100644
--- a/2020/02-Password_Philosophy/first.hs
+++ b/2020/02-Password_Philosophy/first.hs
@@ -25,15 +25,12 @@ parseRule = do
void (char ' ')
e <- anySingle
void (string ": ")
- pass <- (many letterChar)
+ pass <- (some letterChar)
void (char '\n')
return Rule { lower = read l, higher = read h, elt = e, pass = pass }
parseRules :: Parser [Rule]
-parseRules = do
- rules <- many parseRule
- eof
- return rules
+parseRules = some parseRule <* eof
parseInput :: String -> IO [Rule]
parseInput filename = do
diff --git a/2020/02-Password_Philosophy/second.hs b/2020/02-Password_Philosophy/second.hs
index 973a818..35ec555 100644
--- a/2020/02-Password_Philosophy/second.hs
+++ b/2020/02-Password_Philosophy/second.hs
@@ -25,15 +25,12 @@ parseRule = do
void (char ' ')
e <- anySingle
void (string ": ")
- pass <- (many letterChar)
+ pass <- (some letterChar)
void (char '\n')
return Rule { lower = (read l) - 1, higher = (read h) - 1, elt = e, pass = pass }
parseRules :: Parser [Rule]
-parseRules = do
- rules <- many parseRule
- eof
- return rules
+parseRules = some parseRule <* eof
parseInput :: String -> IO [Rule]
parseInput filename = do