projects
/
advent-of-code-20.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bits of tidying
[advent-of-code-20.git]
/
advent02
/
src
/
advent02.hs
diff --git
a/advent02/src/advent02.hs
b/advent02/src/advent02.hs
index 27886d05744f8c57507ef52f379f24b6e0b7f1fa..b4a8e434c1cdf9a75a6f2112d23f74110b7ed022 100644
(file)
--- a/
advent02/src/advent02.hs
+++ b/
advent02/src/advent02.hs
@@
-23,7
+23,6
@@
main =
let policies = successfulParse text
print $ part1 policies
print $ part2 policies
let policies = successfulParse text
print $ part1 policies
print $ part2 policies
- -- print $ head $ part2 nums
part1 = length . filter inRange
where nCharsPresent p = length $ filter (== (character p)) (password p)
part1 = length . filter inRange
where nCharsPresent p = length $ filter (== (character p)) (password p)
@@
-42,7
+41,7
@@
matches p = ((pw!!l) == c) /= ((pw!!u) == c)
type Parser = Parsec Void Text
sc :: Parser ()
type Parser = Parsec Void Text
sc :: Parser ()
-sc = L.space
(skipSome spaceChar)
CA.empty CA.empty
+sc = L.space
space1
CA.empty CA.empty
-- sc = L.space (skipSome (char ' ')) CA.empty CA.empty
lexeme = L.lexeme sc
-- sc = L.space (skipSome (char ' ')) CA.empty CA.empty
lexeme = L.lexeme sc
@@
-56,9
+55,8
@@
passwordP = some alphaNumChar <* sc
policiesP = many policyP
policyP = Policy <$> integerP <* hyphenP <*> integerP <*> characterP <* colonP <*> passwordP
policiesP = many policyP
policyP = Policy <$> integerP <* hyphenP <*> integerP <*> characterP <* colonP <*> passwordP
--- policyP = (,,,) <$> integerP <* hyphenP <*> integerP <*> characterP <* colonP <*> passwordP
-
--
successfulParse :: Text -> [Policy]
+successfulParse :: Text -> [Policy]
successfulParse input =
case parse policiesP "input" input of
Left _err -> [] -- TIO.putStr $ T.pack $ parseErrorPretty err
successfulParse input =
case parse policiesP "input" input of
Left _err -> [] -- TIO.putStr $ T.pack $ parseErrorPretty err