From: Neil Smith Date: Mon, 28 Dec 2020 16:17:45 +0000 (+0000) Subject: Done day 19, but not sure why attoparsec isn't working X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=cc6239892b5dea639d6787a53bffef90a5cf2841;p=advent-of-code-20.git Done day 19, but not sure why attoparsec isn't working --- diff --git a/advent19/package.yaml b/advent19/package.yaml new file mode 100644 index 0000000..1feb922 --- /dev/null +++ b/advent19/package.yaml @@ -0,0 +1,77 @@ +# This YAML file describes your package. Stack will automatically generate a +# Cabal file when you run `stack build`. See the hpack website for help with +# this file: . + +name: advent19 +synopsis: Advent of Code +version: '0.0.1' + +default-extensions: +- AllowAmbiguousTypes +- ApplicativeDo +- BangPatterns +- BlockArguments +- DataKinds +- DeriveFoldable +- DeriveFunctor +- DeriveGeneric +- DeriveTraversable +- EmptyCase +- FlexibleContexts +- FlexibleInstances +- FunctionalDependencies +- GADTs +- GeneralizedNewtypeDeriving +- ImplicitParams +- KindSignatures +- LambdaCase +- MonadComprehensions +- MonoLocalBinds +- MultiParamTypeClasses +- MultiWayIf +- NamedFieldPuns +- NegativeLiterals +- NumDecimals +# - OverloadedLists +- OverloadedStrings +- PartialTypeSignatures +- PatternGuards +- PatternSynonyms +- PolyKinds +- RankNTypes +- RecordWildCards +- ScopedTypeVariables +- TemplateHaskell +- TransformListComp +- TupleSections +- TypeApplications +- TypeFamilies +- TypeInType +- TypeOperators +- ViewPatterns + +executables: + advent19: + main: advent19.hs + source-dirs: src + dependencies: + - base >= 2 && < 6 + - text + - containers + + advent19atto: + main: advent19atto.hs + source-dirs: src + dependencies: + - base >= 2 && < 6 + - text + - attoparsec + - containers + advent19mega: + main: advent19mega.hs + source-dirs: src + dependencies: + - base >= 2 && < 6 + - text + - megaparsec + - containers diff --git a/advent19/src/advent19.hs b/advent19/src/advent19.hs new file mode 100644 index 0000000..01e872d --- /dev/null +++ b/advent19/src/advent19.hs @@ -0,0 +1,87 @@ +-- import Debug.Trace + +import Text.ParserCombinators.ReadP +-- import Text.ParserCombinators.ReadP ((+++)) +import Data.Char (isDigit, isAlpha) + +import qualified Data.IntMap.Strict as M +import Data.IntMap.Strict ((!)) + +import Data.Functor (void) +import Data.Either + + +data Rule = Letter Char + -- | Then2 Rule Rule + -- | Then3 Rule Rule Rule + | Then [Rule] + | Or Rule Rule + | See Int + deriving (Show, Eq) + +type RuleSet = M.IntMap Rule + + +main :: IO () +main = + do text <- readFile "data/advent19.txt" + -- print text + let (rules, messages) = parse inputP text + print $ part1 rules messages + print $ part2 rules messages + -- print $ part2 text + +setup fname = + do text <- readFile fname + let (rules, messages) = parse inputP text + let newRules = parse rulesP "8: 42 | 42 8\n11: 42 31 | 42 11 31" + let updatedRules = M.union newRules rules + let myParser = makeParser updatedRules (See 0) + return (myParser, updatedRules, messages) + + +part1 = countMatches + +part2 rules messages = countMatches updatedRules messages + where newRules = parse rulesP "8: 42 | 42 8\n11: 42 31 | 42 11 31" + updatedRules = M.union newRules rules + +countMatches rules messages + = length $ filter ((== "") . snd) results + where myParser = makeParser rules (See 0) + results = concatMap (readP_to_S myParser) messages + + +parse :: ReadP a -> String -> a +parse parser str = fst $ head $ filter ((== "") . snd) $ readP_to_S parser str + + +-- Generate the rules + +makeParser :: RuleSet -> Rule -> ReadP () +makeParser m (Letter c) = void $ char c +makeParser m (Then rs) = mapM_ (makeParser m) rs +makeParser m (Or a b) = (makeParser m a) +++ (makeParser m b) +makeParser m (See i) = makeParser m (m!i) + + +-- Parse the input + +rulesP = M.fromList <$> ruleP `sepBy` endOfLine +ruleP = (,) <$> decimal <* (string ": ") <*> ruleBodyP +ruleBodyP = choice [letterRuleP, orRuleP, thenRuleP, seeRuleP] + +letterRuleP = Letter <$> between (string "\"") (string "\"") get +orRuleP = Or <$> thenRuleP <* (string " | ") <*> thenRuleP +thenRuleP = Then <$> seeRuleP `sepBy` (string " ") +seeRuleP = See <$> decimal + + +inputP = (,) <$> rulesP <* blankLines <*> messagesP + +messagesP = (munch1 isAlpha) `sepBy` endOfLine + +blankLines = skipMany1 endOfLine + +decimal = read <$> many1 (satisfy isDigit) +endOfLine = char '\n' diff --git a/advent19/src/advent19atto.hs b/advent19/src/advent19atto.hs new file mode 100644 index 0000000..b322324 --- /dev/null +++ b/advent19/src/advent19atto.hs @@ -0,0 +1,104 @@ +-- import Debug.Trace + +import Data.Text (Text) +import qualified Data.Text as T +import qualified Data.Text.IO as TIO + +import Data.Attoparsec.Text +-- import Data.Attoparsec.Combinator +import Control.Applicative +-- import Control.Applicative.Combinators + +import qualified Data.IntMap.Strict as M +import Data.IntMap.Strict ((!)) +import Data.Functor (void) +import Prelude hiding (take) +import Data.Either + + +data Rule = Letter Char + -- | Then2 Rule Rule + -- | Then3 Rule Rule Rule + | Then [Rule] + | Or Rule Rule + | See Int + deriving (Show, Eq) + +-- data Tree = TEmpty +-- | TLetter Char +-- | TThen [Tree] +-- deriving (Show, Eq) + + +type RuleSet = M.IntMap Rule + + +main :: IO () +main = + do text <- TIO.readFile "data/advent19b.txt" + -- print text + let (rules, messages) = successfulParse inputP text + let messagesT = map T.pack messages + -- print rules + -- print messages + print $ part1 rules messagesT + print $ part2 rules messagesT + -- print $ part2 text + +setup fname = + do text <- TIO.readFile fname + let (rules, messages) = successfulParse inputP text + let messagesT = map T.pack messages + let Right newRules = parseOnly rulesP "8: 42 | 42 8\n11: 42 31 | 42 11 31" + let updatedRules = M.union newRules rules + let myParser = (makeParser updatedRules (See 0)) <* endOfInput + return (myParser, updatedRules, messagesT) + + + +part1 = countMatches + +part2 rules messages = countMatches updatedRules messages + where Right newRules = parseOnly rulesP "8: 42 | 42 8\n11: 42 31 | 42 11 31" + updatedRules = M.union newRules rules + +countMatches rules messages + = length + $ filter isRight + $ map (parseOnly myParser) messages + where myParser = ((makeParser rules (See 0)) <* endOfInput) + + +-- Generate the rules + +makeParser :: RuleSet -> Rule -> Parser () +makeParser m (Letter c) = void $ char c +makeParser m (Then rs) = mapM_ (makeParser m) rs +makeParser m (Or a b) = (makeParser m a) <|> (makeParser m b) +makeParser m (See i) = makeParser m (m!i) + + +-- Parse the input + +rulesP = M.fromList <$> ruleP `sepBy` endOfLine +ruleP = (,) <$> decimal <* ": " <*> ruleBodyP +ruleBodyP = choice [letterRuleP, orRuleP, thenRuleP, seeRuleP] + +letterRuleP = Letter <$> ("\"" *> anyChar) <* "\"" +orRuleP = Or <$> thenRuleP <* " | " <*> thenRuleP +thenRuleP = Then <$> seeRuleP `sepBy` (string " ") +seeRuleP = See <$> decimal + + +inputP = (,) <$> rulesP <* blankLines <*> messagesP + +messagesP = (many1 letter) `sepBy` endOfLine + +blankLines = skipMany1 endOfLine + + +-- successfulParse :: Text -> (Integer, [Maybe Integer]) +successfulParse parser input = + case parseOnly parser input of + Left _err -> (M.empty, []) -- TIO.putStr $ T.pack $ parseErrorPretty err + Right expressions -> expressions diff --git a/advent19/src/advent19mega.hs b/advent19/src/advent19mega.hs new file mode 100644 index 0000000..073d6cf --- /dev/null +++ b/advent19/src/advent19mega.hs @@ -0,0 +1,114 @@ +-- import Debug.Trace + +import Data.Text (Text) +import qualified Data.Text as T +import qualified Data.Text.IO as TIO + +import Data.Void (Void) + +import Text.Megaparsec hiding (State) +import Text.Megaparsec.Char +import qualified Text.Megaparsec.Char.Lexer as L +import qualified Control.Applicative as CA + +import qualified Data.IntMap.Strict as M +import Data.IntMap.Strict ((!)) +import Data.Functor (void) +import Prelude hiding (take) +import Data.Either + + +data Rule = Letter Char + | Then [Rule] + | Or Rule Rule + | See Int + deriving (Show, Eq) + +type RuleSet = M.IntMap Rule + + +main :: IO () +main = + do text <- TIO.readFile "data/advent19b.txt" + -- print text + let (rules, messages) = successfulParse text + let messagesT = map T.pack messages + -- print rules + -- print messages + print $ part1 rules messagesT + print $ part2 rules messagesT + -- print $ part2 text + +setup fname = + do text <- TIO.readFile fname + let (rules, messages) = successfulParse text + let messagesT = map T.pack messages + let Right newRules = parse rulesP "rules" "8: 42 | 42 8\n11: 42 31 | 42 11 31" + let updatedRules = M.union newRules rules + let myParser = (makeParser updatedRules (See 0)) -- <* eof + return (myParser, updatedRules, messagesT) + + + +part1 = countMatches + +part2 rules messages = countMatches updatedRules messages + where Right newRules = parse rulesP "rules" "8: 42 | 42 8\n11: 42 31 | 42 11 31" + updatedRules = M.union newRules rules + +countMatches rules messages + = length + $ filter isRight + $ map (parse myParser "message") messages + where myParser = (makeParser rules (See 0)) -- <* eof + +prettyResults rs = map p rs + where p (Left e) = errorBundlePretty e + p (Right r) = "^" ++ show r + + +-- Generate the rules + +makeParser :: RuleSet -> Rule -> Parser () +makeParser m (Letter c) = void $ char c +makeParser m (Then rs) = mapM_ (makeParser m) rs +makeParser m (Or a b) = (try (makeParser m a)) <|> (makeParser m b) +makeParser m (See i) = makeParser m (m!i) + + +-- Parse the input + +type Parser = Parsec Void Text + +sc :: Parser () +sc = L.space (skipSome (char ' ')) CA.empty CA.empty + +lexeme = L.lexeme sc +integer = lexeme L.decimal +symb = L.symbol sc +colonP = symb ":" +pipeP = symb "|" +quoteP = symb "\"" + + +rulesP = M.fromList <$> ruleP `sepEndBy` newline +ruleP = (,) <$> integer <* colonP <*> ruleBodyP +ruleBodyP = choice [(try letterRuleP), (try orRuleP), (try thenRuleP), (try seeRuleP)] + +letterRuleP = Letter <$> between quoteP quoteP letterChar +orRuleP = Or <$> thenRuleP <* pipeP <*> thenRuleP +thenRuleP = Then <$> some seeRuleP +seeRuleP = See <$> integer + + +inputP = (,) <$> rulesP <* (some newline) <*> messagesP + +messagesP = messageP `sepBy` newline +messageP = some letterChar + + +-- successfulParse :: Text -> (Integer, [Maybe Integer]) +successfulParse input = + case parse inputP "input" input of + Left _err -> (M.empty, []) -- TIO.putStr $ T.pack $ parseErrorPretty err + Right expressions -> expressions diff --git a/data/advent19.txt b/data/advent19.txt new file mode 100644 index 0000000..273c118 --- /dev/null +++ b/data/advent19.txt @@ -0,0 +1,626 @@ +25: 53 116 +122: 116 92 | 53 53 +100: 53 73 | 116 125 +111: 67 116 | 91 53 +71: 116 58 | 53 78 +55: 116 54 | 53 21 +123: 53 97 | 116 108 +104: 56 116 | 125 53 +19: 125 53 +56: 116 116 | 116 53 +60: 116 121 | 53 59 +75: 53 20 | 116 124 +6: 53 131 | 116 33 +62: 53 53 | 116 116 +101: 116 127 | 53 26 +128: 116 125 | 53 93 +34: 53 28 | 116 125 +65: 63 116 | 135 53 +50: 32 53 | 76 116 +2: 53 10 | 116 132 +133: 28 53 | 131 116 +85: 53 131 +125: 116 53 +118: 87 116 | 3 53 +135: 73 53 | 125 116 +28: 53 53 +110: 116 122 | 53 56 +91: 5 53 | 74 116 +73: 92 116 | 53 53 +80: 15 116 | 109 53 +124: 128 116 | 17 53 +87: 92 53 | 53 116 +43: 116 27 | 53 37 +66: 46 53 | 93 116 +106: 116 77 | 53 83 +137: 72 116 | 104 53 +93: 116 116 | 53 116 +129: 92 103 +12: 116 56 | 53 131 +45: 53 132 | 116 12 +102: 65 116 | 2 53 +24: 116 101 | 53 95 +14: 116 84 | 53 29 +57: 93 116 | 56 53 +70: 108 116 | 100 53 +51: 116 1 | 53 68 +26: 73 53 +15: 116 93 | 53 125 +42: 53 134 | 116 106 +79: 116 33 | 53 122 +5: 116 125 | 53 3 +74: 53 122 | 116 73 +18: 93 53 | 87 116 +20: 47 53 | 17 116 +114: 116 85 | 53 118 +37: 53 73 | 116 87 +47: 116 73 | 53 125 +107: 116 3 | 53 46 +69: 53 25 | 116 125 +32: 53 28 | 116 93 +76: 3 53 | 125 116 +38: 92 33 +119: 116 39 | 53 80 +8: 42 +21: 125 53 | 125 116 +58: 75 116 | 119 53 +64: 116 44 | 53 113 +68: 90 53 | 45 116 +1: 23 116 | 60 53 +53: "a" +81: 73 53 | 33 116 +86: 116 129 | 53 35 +90: 110 116 | 13 53 +82: 53 93 | 116 25 +95: 99 116 | 66 53 +27: 116 56 | 53 3 +120: 116 51 | 53 40 +126: 116 96 | 53 52 +116: "b" +84: 116 123 | 53 49 +134: 116 61 | 53 14 +78: 116 102 | 53 86 +96: 130 53 | 98 116 +10: 87 116 | 33 53 +88: 53 116 | 116 92 +40: 126 53 | 24 116 +127: 56 116 +59: 87 53 | 3 116 +11: 42 31 +41: 116 137 | 53 16 +44: 116 22 | 53 79 +109: 88 53 | 87 116 +49: 136 116 | 94 53 +113: 107 116 | 81 53 +77: 116 64 | 53 36 +3: 53 116 | 53 53 +9: 133 53 | 112 116 +98: 92 93 +117: 3 92 +39: 53 19 | 116 21 +16: 6 116 | 117 53 +132: 131 116 | 125 53 +63: 116 122 | 53 33 +22: 131 116 | 56 53 +89: 116 125 | 53 131 +115: 55 53 | 50 116 +99: 116 33 | 53 93 +92: 116 | 53 +121: 53 73 | 116 56 +13: 73 92 +103: 53 3 | 116 62 +83: 111 116 | 41 53 +61: 105 116 | 115 53 +130: 56 92 +136: 33 116 | 125 53 +30: 53 76 | 116 7 +94: 92 87 +52: 97 116 | 18 53 +7: 116 28 | 53 46 +97: 25 53 | 33 116 +35: 89 116 | 82 53 +72: 53 131 | 116 87 +48: 34 116 | 38 53 +54: 116 46 | 53 131 +131: 116 116 +23: 116 4 | 53 57 +31: 116 71 | 53 120 +29: 116 30 | 53 114 +108: 116 25 | 53 46 +33: 92 92 +4: 131 116 | 3 53 +36: 70 116 | 9 53 +67: 69 116 | 117 53 +0: 8 11 +105: 48 116 | 43 53 +46: 116 53 | 53 116 +17: 93 116 | 122 53 +112: 122 53 | 3 116 + +babbbbabaabaaabbbbbaaabbbbababba +ababaaaaabbbabbbbbabbbba +aabbaabaabbababaababbaba +bbbbabaaabaaabbbbbbbbaab +babbbabababaabbaaaabbbba +bbaabbababbaaabaaaababbbabaaaaaaaaaaababbaabbbbaaaaaaabaabababbbbabbbaababbbaabbbbababab +babbabbabbaababbbbbbbaab +baababababbaababaaabaaab +aababaababbaaaabbbababbbbbbbbbaabbbbabbbbbabbababbababaabaabaaaabbabaaaaabbaaaaa +baabbbbaaabbabbbababbbba +baabbabaaaaababbaababbbbaababaaabbbbbaaabababaab +babbabbabaabbabbaabbabaa +baaabbbbabbaaabbaaaaaabbbbabaaba +abababbaaabaabbbabbbaaaa +ababababbbbaaaababaabaaa +baaababbbbbabababbbaaabaaaabaababaaabbbbaaabbbbaabbaabbbabbbaaab +babaaabaabbabaababbabaaaabbbaaaa +ababaaabaabaabaabbbbababbbaabababaababaaabaabbbb +abbaaaabaabababaabaabbaa +baaaaaabaaaaababbababaaa +aabaaabbababaabbbaaabbbbaabbbaaa +baaabbbaaaaaaaaaaabbbbba +abbbbbabbbbabaabaabbbbabbbaabaabaabbbbbb +baabbbababababbabbaaaaaaabbbaabbbababbbaababaaaaaabbbbaa +bbbbbbbbabababaabaaabbbabbaaabbbaaaaaabaabbaabbabbabbbba +abaabbabaabaaaaabaabaaaa +aabababbababaaaaabbbbbaa +bbbabbaaabaaaababababbbabbbaabab +aabababbaabbbababaabaaab +aabaaababaabbabaaabaaaab +abbbabaabbaabbabaaabbbba +baaabbbbaababbabbbbabbaabaabbbbbabbbbabbbabbaaba +bbaaababaabaaabbabbbbbabbabaaabbbbaabbbbaabbbaaabbabbabb +baabaabaaababbbbbbaabbaa +bbaaabbbbababbabaaaababa +bbabbbbabaaaaabbbaaaaababbbbbaaabaababbbbabbabaabaabbabaabbababbaaaaaaabbbabaaabbbbbbabb +abaabbbababaaaabaabbbbbbbbabbbab +ababaaaaabababbabbbaababbaaabbaaabbaaaba +bbabbaabababbabbbaaaaaabaaabaabb +baabaaaaababbbbabbabbabbbababbaa +aaaaaaaabaaabaabababaaba +baabbababaaabaaaaabaabaaaababbbbaaabbbbb +abaaaabaabbababaababbbab +bbaaabababbababbababbbbb +baababbaaaabababbaaaaaabbaaaabbb +bbbbbbbaabababbabbabbbba +bbaaaaaaaabaabbbabaabbaa +abbabababbaaaaababbbabbbbbaaaaaaababaaaababaaaba +abaababbaabaaaaaaabaaaab +abababaabbaaabbaabababbaaabbabaa +babbabbbbbbbbbbabbaabbaa +bbabbbaaaabaaababbaaababbaaabaabaabbbaababbaabaaaabbbaaaabbaabbbaabbbbba +abbbaabbababaaabbababbbaabbbbababababaaa +bbaaabbabbbaabaaabbbabaaaaababbbbaababbb +baabaaaabbaaabbaaabbaababbbbbbababbbabbbbbbabbba +abaabbbaabaababaaaabbabb +bbbbabaaaabaabbbbbbbbaab +bbaaaaabababbabbaababbab +babbaabaabbbbaaaaabbbbbb +baaabaabbbbbaaaaabbbaaab +aaabbaabbabbabbbbabbbbba +aabbababaabababaaabbabbbbbbbbbbaaaabbaaaababbabbabaaabaabbababaabbbbbabbbabbbbabaabaabaabaababba +ababaabbaabbbabababbabab +bbbabbbabaaabbbaaaabbbab +aabababbaabaabaaabaaabbbaabbbaaa +aaaaaabaabbabbaabbbbaaaaaabbaabbaaabaaaaabbbbaabaaaabbbaababbbbbababbaaa +ababaabbabababbabababbbaaabababaaabbbbaaaabbbabb +babbabbaabbabbbaababaaba +abbbbaaabbbbbbbabbababbbbaabbaab +babbaabaabbbbabbaaaaaaabaabbabba +bbaaababbaabbabbbbbbabbbbabbabaabbabaaaa +aaabaabaaabbababbababaab +bbaaabbbababaabbaabaaababaabbbbbbbabbaaa +abbabbbabaaabbbbbabbbabaaabbaabababbbbbaabbbaabababaabba +aaaaaaaaabbabbaabbabbbaaaabababbbaaabaababaabbaabbababab +aabbbabababbabaaaaabababbabbbbba +abbababbbbbbabbaaabbbbbb +bbbbbbbaabaaaaababbaabbb +aabababbabaaabbaababbaaabbbbababbbabbabbbaaababbabbbbbabaaabaabaabbabaabaaabbaaa +abbbbbabbbbbabaaabaabaab +abbabbbabbbbabababbbbbba +abababbabaaaaaabbbabaaaa +aaaaababbbbbaabbaaabaabaabaaabababbabbabbbbaabbb +baabbbbabbbaaaaababaaabb +bbaaaababbaaaabaababaaaaaabbbaabbbbabaaa +babbbbbbbabbbaaabababaabbabbbaabbbaaabaa +aabaaabbaabbaabbbababaab +baaaabbbbbabbbababbaababbabaaabaabababbaabaabbabbaaaaabaabbaaabb +abababbabaabbbbaaaaababa +aabbbbabbbbbaabaaaabbaabbbabaabababbbbaabbaabbabbaabbaaa +aaabaabaaabbababbabbbababaabbabb +bbbaaababbbbbbbbbbbababbabbbaaab +bababbaaaaaabbbbbabaaaab +bbaaaabaaaaaaabababbbabaaaaabaaa +aabbabbbbbaaababbbababaa +abbaaaababbbbbabaaaaabbb +bbaaaaaabbbaabababaabaab +ababaabbabaababbbbabbaabbbbbbbbbaaabbababbabbabbabbaabaa +bbaabbbaabababbaaaababbb +bbbbabbaaabaabaababaaaaa +bbaabbababbbbaabbababbbabbbbababbbbaaabbbaaaababaababbbababbaabb +bbaaaababababbabbabbbbaaabbbaaab +babaababaaabbaabbbababaa +ababababababbaabbabababa +abbabbbbaaaaaabbabbbabaababaabbaabbbababbbbaabaaaaaaaaabbbaabbba +bbbaaabaaaaaaaaaababbabbbbaabaab +abbbaabbabbbbaaaaaaabaab +abbbbbbbaaabbbbaaaababbaaaaabbabbababaabbbaabbabaabababa +aababbaaabaababbababaabb +babbaaabaabbabbbbbabbaaaaaaabaab +aabababaabbbbabbaaaaabaaaabaabababbaaaba +baabbabbbbaaabababaabbbb +abbaaabbbbbabaabbbbbaabbabbbbaabbaabaaabaabaaaab +bbaabbbabbbbbabbbababbbb +babaababbbbababaabaaaabbbabbabaabaabababaabababb +bbababbabbaabbbbbbbbabbbabbaabaaabbbaaaabbaabaababaaaaaa +babbbbabbbbbbbaaababbbba +abbbbababbbaaaaaaaabbbab +baaaaaabaabbbaabbabbbabbabbaaabaababbaaaabbaaababbaaaaaabaaaaaabbaababababaaabbbabaabaaa +aabaabbbabbbbaaaaababbaaababaabbabbbabbababaabba +aabababbbbbbabbaabbbbbbb +baabababbbaaaaababbbbaabbabbabbbaaababbaaaabaaab +baaabbbababbaabaabbabaaa +abaababbabbbbaabaababbbbbbbaaaab +aababaababbbabbbababbaaa +baaabbbbbbbbabbabbbbbaab +bbabbaabaaabbbaaaabbbaaa +bbabaabaababbaababbbabbbabaabbabbaabbaab +bbbbbbbaaabbaabaababaaba +aababababaaabbbaababbbaa +babbbbbabbbababbaaababaaaababbaaaaabbbabaaababaaabbbbbbbbbbaaaabbaaabbaabaaaababbbaaaaab +aababbaaabaaaababbbbabaaabbbbabaabbbbabbbabbbabb +bbbaabaaaabbbbabaababbaabbabaababbaabaaaababbbba +abaabbbaabbbaaabbabaaaab +bbbbbbbbaaabbabababaaabbbbaaaabbbabaaabb +baaaaabbbaaaaabbabbaaaaa +ababaaaaaabbbaababbaabba +bbaaaaaaaaabbababaaaaaaaaabaaaab +bbbabababbbbabbaabaaaaaa +bbaaaababaaabbbabbbabaabaabaabab +bbbabbbaaabbbbaaabbaabbaabaabbbaaabbbbba +babbabbabbbbbbbaaababababaaabaabbaaaaaabaaaaabaaabbbbbbaaabbbbbabbaabbaa +ababbabbaabbaabbbaaaaabbaababaaaabbabbab +abbabbbbbaabbbbbbabaabbb +abbbaabbaaaaababbbaabbabaababaabaababaababbbbbbbbbaabaab +baaaaaaabbbabbbaaaabbbba +bbaaabbbababbbabbaaaabaabaabbabbbbbbbbbbabbabbabbababababbaababbbbabbaba +bbbbababbaabbababbabbbab +baaabaabaababbbbbbabbbbb +abbbbababbbababbbbabbababbabaabbbbaaaabb +bbaaaaaaabbbabbbabbbbbaa +bbabaabaabbabbaaababbbaa +aabbbaababaabbabbabaabba +baaabbbaaaabaababbaaaabb +babbbbaabbbbaabaabbbaaaa +abbaabbbaababbabbaaabbababbbabab +aaabaaaaaabbabababbbbabbbbabbbbbaaabaaab +babbbaababbaaaaaaabaaababbaaabbb +bbbbaababbaaaaaabbbbbaab +bbaaaaaaabbbbababaabaaab +babaababbabbabbbaabababaabaabaab +abbbabbbabbabbaaaababaababbabaab +bbbbaaaaaabbaababbabaaabbbabaaaabbabbabb +aaabbaabbaaabbbbbbbbbaaa +abbbbaabaabbbabaabaaabababaabbba +babbabbabaaababbbbaaabbababaabaabaabbaababaabaaa +babbabbaaabaabbaaaaaabaaabbbaabaabbaaaaabbbaaabaaababbaabbbbaabaabbbbaba +aabaaabbabbaaabbbabbbabb +bbaaaaaabaabbbbaabbbaaab +bbbbaaaabbbaaabaabbbbabbbababaaa +abbbabaabbabbaabbabbbbba +aaaaaaabaababbbbababbbab +abbbababbbabbbbabbbbbabbbabaaababbababaabbbaaaab +babaaabaaabbbaaaaabbbbbbabbaaaaabaabaabbabbbababaababaaaaaabbaaababbbabbbaaababb +abbababbbaaaaaabbabaaabb +bbabbababbabbaabbababbbb +babbbbaaaabbaaababbbbaaaaabbababaaabbaabbbbbaaab +aabbaabbabaaaabbaabababaabaaaabaaaabaaaaaaabaabababababa +abababbaaaabaabaaaababbb +bababbabaaabbbaaababbbbb +baaaababbabbbabababaabba +abbbbabaaaaababbbbbaabbabaaaabbaaaababba +aabbababbbaababbabaababa +babbaaabbbaabaabbbaaabbabaaaaabaabbabbaabaabbaabbbbbababbbbabbbb +aaabbbaaabbabbabaabaaaaaaabaaaaa +aababbaaaababbbbabbbaaaa +baaabbbabababbbaaabaabba +bbabbaabbbbabaaabaaabbbbbbbaabababbaabbbbabbabbaaabaaabb +baabaabaababababaaabaabb +abbababbbbbbababbbaabaab +abababbabababbabbaaaaaab +bababbbaaabaaabababababb +aabbabbbbaaababbbbabbaaa +abbaaaababbabababbaabbbabbaabaab +bbbabbbaababaaaabbbaaabababbaaaaababbabaaabbabaaaaaaabba +baabaabaababaaabbbbbababbabbabbabababbbb +bbbbbaaabbaababaabbbbbaaababaaba +bbaaaabaabbaaaabbbababbbbbbababaabbabaababbbaaaaabaabaaa +bbabaaaaababbbbbbababbbbbbbababbbabbbbab +ababababbaaabaabbbbaababaababababaabbbaaaaababbbbabaaabb +babbbabaaabbabbbaababbba +aaaaaaaababbbababbaababbabbbaabb +aababababbaaaaaabaaaaaba +aaaaaaabbaaaabaaaababaabbbabbabb +bbabbabbbbbbabbaabbbaabaababbbaabaaabababaabbbbbbabbbbbb +bbbaabbaabaaaabaabaaabaa +babaabbabbabbaaabaabaaaaabaabaaa +aababababbbbaabaabbbbbaa +baabababbaabaabbaaaaaabbaaaaabababbabbaaabbabbaaaaaaabbb +bbabaabaababbabbbabbaabb +abaaaababbbbbbbabbabaaaa +bababbabbbbbabaababbbbbb +aabbabbbbbbbabababbabaab +abbababababbabaaaabbbaaa +aabababbabbaabbbbbbaaaabbbbbaaaa +abbbabbbaaaaaaabbaabbbbb +bbbbbbbaaabaaababbbbababbabaaabaabababbb +aaaababbaaaaaabaaabaabba +abaaaabbbbbbababbbababbbabaabaaababaabaa +bbabbbaaababbabbbbbaaaab +aababaaabaabbbbbbbbabbbb +aabbbaababbbbbabbababaaa +aabbaaababbaababbbbbababbbbbababbbbbaabbbaabbbbbabaabbaabbbabbbb +baaabbbbbbbaaabaabaabaab +baaabbaaaababaabbabaaaaa +aaabababaababbabaababababbbbbbaabbabbbaabaabaabbaaabaabaababbbbb +aabaaabbbaaabaaabbbabaab +bbbaabbaababbabababbbbbababbbabbbbaabbbbbbabaaaaaaaabbab +aabbaaabbbaabbabaaababbb +bbbbabaabbbabbbaaabaaaab +aabbaabbbabaababbaababaa +aaaaaaaababbbbababaaaabaaabababbabaaababababababaaabbabbababbbbbaaaabbab +babbbbabbababbbabaabbaaa +aabbaaabbbaababbbbbbabaaababaabbbabaaabaaabbbabbababbaba +bbbaaaaabbaaabababbabbbb +bbbbabbababbaaaabbbabbbaabbaabbbbbaabaaa +aaaababbabbaababbabababb +bababbabaaabaaabbaabbbaabaaababa +babaababbaaaaaabababbaabbababbaaaaababbb +aabbabababaaabbababaaaba +bbbaaabbabaababbbababbaa +abbabbbaabbaababbabaabba +baaababbaaaaaabaaabbbaaa +baaaaaabaabababbaaabbaabababbaababbaaabbaababbba +abbbbabbbbabbabaaaaaaabbbabbaabb +abbbbaabaaabaababbbababaaabbbaabbabbabbabbabaaababbabbbbbaababaa +bbbabababaabbaaabbaaababbabaaaaabbaaaaaa +abbbbaababbbabbbaabaaaab +bbababaaaaaabababaaabbbbbbabbaaababbabbabaaaababaaaabababbabaabaabaabaab +bbbabbaabbbbabababaaabaa +abaaabbabaaaabaaaaabbabaababbaba +babbaabaabbabbaabaaaaaba +aababababbabbbaaabbaabba +bbbabaabbaaabbbabbabbaaa +bbbababaaabbabababababbb +aabbbbababaaaabbbaabbabbbaabbaab +bbaaaababababaababbbaaab +abbbaabbaaaaabbaaabaaaabbabaaabaaaaabbabbaababaa +babbabaabababbabbbbbabbbaabbbaba +bbbbbbbaabbbaabbbbbabbab +abaabbabbaabaababaabababbbbaaababababbaaaabbbabbabbaabbb +abababbabbaaaaabaabbabba +abbabaaababbababaabaababbabaaaaabbaaabaabbabbaaa +babbabaabbababbbbbabbaaa +aabaaabaababaaaaaaaabbba +bbaabbbabbbbaaaabaabababaabaaabaaabbabba +abaaaabaaabaaabbabbabbbb +abaaaaabaaaaaaaabaaaaaba +aaabbabababbbbaaaaaabbbb +bbbbaabbabaaabababaaabbababbbabaababbaabbabaabba +bbbabbbaaabbbababbaaabbbbbbabbabbbbbbabbabbbbbbb +abaaaababaaabaabababaaba +baaabaaabbabbbaaaabbaababaaaabba +bbbbabbbbbaabbbabaabbbbb +ababbaababbbbabaababaaaaaabbaaabaaaaabbb +baaaababaaaaababbababbaa +aabaababbabbaabbbaabbababaabbaabaaabaaabbabaabbababaaabbabbbaaab +abbabbaaaaaaabbabaaaabbaababbaaa +bbbbaabaabbbbabbaabbabbbaababbbbbabaaaba +bbbaaabbbaaabbbaaaababbb +baaabbbabbbaaaaabbbaaabaaabababbabaaabbababbabab +aabaaabbabaaaaababbbaaab +bbaaaaabaabbabababbbbaaababbababaabaabba +bbaaababbbbbaaaabababbbaaaabbabb +bbababbbbbabbababbbbabaabbbbaaaaaabbbaabbabbabbbbbbabbbb +bababbbaaaabbaabaaaabbba +ababbaababaabbabaaaaabba +aaaaaabaaaabbbaaababbaba +babbbbaaabbbabbbbbbabbab +bbbbbbbabbbbabbbabbaaaba +baaabaaaaabbaabbabaaababaaababbb +baabaabababbabbbaabbbabb +bbaaaaaaabbbbabbabaabbabbabbaaabaaaababaaaaaabba +baaaaaaaaaaaaaaaaaaababa +abbaababaabbbbabaaababba +bbbbababaabbbaabaababbaaaaabaaab +aababaabaabaababbbbbaaaaababaaaaabaababbbabbbbaaabaaaaabababbbab +babaababbbaabbabbbaabbaa +baabbababaaaabaabababbaa +bbaaabbabbaaabbbbbabbabb +baabbbbabbaaaabaaaabbbba +bbababbbbaabbbbaaaaabaab +aaabababaaaaaabbabaaaabababbbbbb +bbbbbbababaaabbbbaaaaaaabbaabbaabbbbbaabaabaaabbaaabbbbabbaabaabbbbaaabbabbbaabb +aabbbaaababbabbbbaabbbbababaaaaababaaaaaaaababbbaabababb +bbabbaabbabbaaaaaaaaabba +abbabbaabbaabbabaaabaabaabbaaaaaaabaaaabbbaabaabaabbabaa +abaababbaabbaaabaaabaaaabbaaaabaabaaababaababaaabbbabbababaaabaaabbaabbabbaaabaa +bbaaaaabbbbbabaaaababbaababbabbbaaabbabababbababbabbbbba +babbbbaaaababbaaaabaabbbbaabbbaababbbbbb +aaaababbbbbbbbaabbbabbbb +bbaaababbbaaabbaaabbbabb +abbaaabbbabbaabababaabbb +aabababbabbbbbababbbaabbaaabaaaaabbabbaababaabaabaaaaabaaababbbaababbbab +babbaaaaaabbbbabbbbbbbaabaabbbabbbbbaaab +babbabaaabbaaabbbabaaaaa +aaaaaaabababababbaababbb +ababaabbbabbaaaaabbbbbbb +aabbaaabaabbbabaaaababba +baabbabaaabaabaaabbaaaaa +abaaaabaaabbbaabbabaabaa +bbaaabbbbaaabbbaababbbbb +baaababbbbbaababbbabbaaa +ababbbbbabbababbaaabaabbaabbbaaaaabbaaabbbbbababbaaaaabaaabbbbaaaabbabaaaababbbbabaabaaa +bbbbabbbababababbaabbaab +ababbaabbabbbbaababbabbabaaabbaabaaabaaabaaaabbbababaababaababbb +baaaababbabbbbabbaabbaab +bbaabbbaabaaabbbbababbaa +bbabbbbaabbaaabaabbaabbaabaabbbb +bbbaaaaabbaababbbbaabbababaababbabbaaaba +aabababbaaabbbaaababaabbabbbbbba +abaaaabaaaabaaaabaaaababaabbbaababaabbabaaaaabbaaababbbabaabbaaababaaaab +baaabbbbbababababaaaababbbbaabaaaabaaabbbabbaabbabbbabaabbaaaaba +abbbbabbbbbbabbbbabbbbbb +bbbbabbbabbaaabbbbabaabaababaababbaaaabb +ababaaaaaababaabbaabbabaabbbabaaababbaaaabbbaaaa +bbbbbbbbbbbbaabbaaaabaab +aababaabbabbabaaaaaabaab +ababaaababbabbbabbaabaaa +bbbababbabbbbbabaaaaabaa +abbbaabbbabbbbabaaabbaaa +abbaaaabbbaaaaabaabaabba +aaabbabaaabaabbbaaabbabb +ababaaababbbbaaababaababbbbaabbbbaabaaaa +baabababbaababbabaabbaab +bbaaabbbaaabaabaababbaba +baaaaabbbbbaabaabaaabaaabaabbbbb +aabbbababaaaaaabababbaaa +baaaababbaaababbaaaaabaa +aabababaabaabbababababbb +bbaaaaaabaababbabbbbabaabbbbbbaaaabbaaabbababaab +bbbbababaabababaaabbbaaa +baaabaababbabbbaaababbaa +babaaaaaabbaababaaabbbbaabababbababaaaababaabaabbbbaabbbaaaaababaabaabbabbbbbbbbabababbaabaaaaab +bbbaababbaabbbbabaaaabaaabbbbbba +aababaabaababaaabbbaaababbbabaabbbaabaab +bbbbababaaabaaaabbbaaaab +bbbbbbbbabbbabbbaababaabbbabbabbbbaabaab +baaabaaabaaabbbbaabaaabbaaabaabaaabbbbaa +bbbabaabbaaaababaaabaaab +ababababbbbbabbbaaabababbaabbaab +abbababbaababaaaaababbaa +ababababaabbaabbbababaaa +ababbabbaaaaaabbababbbab +aaabbabbbaabababaabbaabbaaabaabbbabbaabb +bbbbababaabaaaaaabaaaaaa +bbaababaababbaabaaaabaaaaabbabaabaaaaaaaaabbaaba +bbababbbbaaaaabbaaababba +bbbbbbaaabbaababbaaabbaaabbbbabababbbbba +aabbbaabbbbababbbaaababa +aabaabaabaaabaababbabbbb +bbbbabaabaabbbbababaabab +abbbaaaaaabbbbbababbababbaaaabba +aaaaaaabaaabaababbbaaaaaaabbbbbbbbaabaaaabbaaaba +baaabbabbaaabaababbaabababbabbbabaabababaaababbbbbabbaabaabbbabb +aaaaababbaaabbaabbaaaabb +bbbabbbabaabbabaabbbabbaababaaaabbbbabbabbaabbaaaabaaabbabbbbaab +baabaabaabbbbbababaaaabbbbbabaabbbbaaaabbbbbbaabbaabbbbb +bbaaaaaabbabbaabbaabaaba +abbababbbabbbbabbaaaaaabaaaaaabaaaaaabbb +abaababbaabbbaabbabaabbb +baabababbaabababbbbaaaaabbababbbbaaaabbb +baabaabaabaabbbbbaabababbabababbbbabbbaabaaaaabaaaaabaaababbbbababbbaaabbbabaaba +abbbbaaaaaabbbaabaaaabaaaaaabbaa +baababababbaaabbbabbaabb +aaaaaabaabababbabbabbbbb +aaabbabaaabbaabbbbabaaab +abbbaabbbbbbabaaaaaabaaa +aabbabbbabaaaabbaabbbaaa +aabbababbaaabbbbabbbbbabaabaabab +bbbaababaabbbbbabbabaaaabaaaabba +bbbbababaabababaaabbabaa +ababaabbbbbbbbbaaaaabbbb +aaabababbabbaaaaababbbbb +bbbbabbabbbbbbaaaabaabbbbabbbbba +bbbababbaaababababbaababbbabbaabbabaaabaabbabaab +baaabbbaabababbaababbbaa +aaaaaababbbabbaaaabaaaaaabababababbaabaababaaaba +bbabbaabbbbbbbaabbbaaaab +babbaabaabbaaabbbbaabbbaabababbaaaabbbaabaababbbabbbaaaa +baabaabbbaaababababaaabbabbbbaaaaabaaaaababbabaaabbbbbbabaabaababbbbbaaabaaaaaaa +abbaababbbbabaabababbaba +bbaababbababababbbbbbaab +bbbbaababbaaaababaaabbaaabaabbbbbbbbbaaa +babbbaaabaababaababbbabbabbaabbabbaaaabaaababaababaabaaaabbaaaba +bbababbbabaaaaabbbbbbabb +babbabbbababaaaababbbabaaaabbababbabbbbbabababbb +abbbaabbbbaaabbbaaabbabaaaaaaababaabaabbaabbbaabababbbabbbbbbbabababbbbbaaababaa +aaaaabbabbbaaaabbaaababbbaaaababaaabbabbbabbabbaabbabaabaabbaaaaabbaabaababaabaababbabaa +baaababaababbbabbaaaabbaababbaaababababababbaabbbbbabbbababbababaaabbbbaababbaba +babbabbaabbbabaaabbaaaaa +bbbaaabaaaabababbaaabbbabababbbb +bababbbaababaaaabaabaabaaabbabbbbbabababbabbbaab +aababaaaabaabbabbabaabaa +aababbaaaaabbaabaaaababa +babbbbaababbbbaaaaabbbaabbaababbbbabaaabbaaabbabababbbaa +abaaaababababbabbababbbabbabbaabbbaaabaa +aabbababaabbaababaaaaabbbabbaaaabababbabbbbabbaaaaabbbbb +aabaaababbaaaabbaabbabaaaaababbabababbbb +abbbbbaabbbabaaaaaaaabbaaabbbaaa +bbbbabaaaabbbababbbabbbb +bbbababaababaaabaabbabaa +abaababbbaaababbbabbbbaaabaabaab +aaabbaababbbbaaaaabbbbba +aabaaaabababbaaaaaabaabbaaaabbaa +baaabbabbbabaaabaaaabaabababbbbb +abaaaaabbbaaaaaabaababaa +bababbabbbbabbaaaaabbbab +abaaababbaabbabaaabaaabbabbbbabaaaaababaaabaaaabbbbabbbbbaabbaaa +aabababbaaabaaaaabbaabba +ababaaabbabbabaabbbaaaaaaaaaaabbaaabaaab +aabaaababbbababaaabaabaabbbbaaaaaabbaaaa +bababaaabbababbabbbabaaa +abaaabbabaaabaabbababbaa +abbbabaabbaabbbababbbbbb +aabbbbabbaaabaaabbaaabaa +bbbbabbaabbbbbbaaaababaa +abbbbabaaabababbaaabbbbb +abaaabbaabaaabbbbbaabbbb +aabaaabaaaaaaabaaaaabbba +abbabbbaababbabbaaaabbbb +babbaabaaaaaaaabbaabbbbabaaaababaabbaaaa +ababbabbabaaaabbbbbababbaabbababbbbababb +abbbabbbbabbbbabbbaabaab +baaababbbbaaabbabbbaaaab +abbbbaabbbbbaabbabaaababbaabaaab +bbbbababbbaaabaaabbababbbabbbbababaababaaaabaaaabaaaabaaabbbaabababbbabbbaaaaaababbaabbb +bbbbabaabbabaabbabbbbbabbabaaabbaabbaaab +baabbabaaabbaababbbbbaab +bbabaaabaabaaaababbbbbaabaaabbaabababbaaaabbaaabaaaababbaaaababaaaaaaaaaababbbbb +abaaaabaabbbabbbaaaaababbaaaaaab +abbbabbbaababbbbabaaaababbaaabbaabbbaabbbbabaaaa +bbaaabbabbaababbbbbabbaabaabbbbabbbaababababbbaa +bbaaaaaababbbbbbbaababaaababbaaabaabaaabbbababbabbabbbbababbaaab +bbaababbbbaaabbbababbaba +bbbaaabbbbbbabaabbabbaaa +bbbababaaababbbbbaababaa +baaaababaababaaaabbbbbbb +aabbbbabaaaababbbabaabba +baaabaabbbbabbbabbaaabbaabbbaabbbbaabaab +aabbbaabbaaaaaaabaaaaabbbbbaabab +baaaabaaaabbaabaabaaababaaaabaab +aaaaaabaaababbaabaaaaaba +aaabaaaaaabbbbabbaabbaaa +abaababbbbbabbbaaaaaaaaaaabaaabbbaabbbabaaabaabb +bbbaabbaabbababaabbabaaa +bbbababbabbabbbabbaaabbabababbaaababbbbb +abaabbbaababbbaaabbabaab +aababaabaaabbababababbbaaaabbabababbbbaaaaaabbbababbabab +bbabbbaaaaaaababbbaaaabababbabaaabbabbbbaaabbbbb +aaaaaabbbbbaaabbbbaabaaaaabbabaa +bbbaabbababbaabaaabbbbbb +abbbabaaaaaaababaababbab +bbabaabaaabbaabbaabbabba +baaaabaaaababaabbbabbbab +bbaabbbaaaabbaaaaaaaabaaaaaabbaa +aabaabaaaababaabbbbaabaabbbaaabbbbabbabb +aaabaabaabbbabbbaabbbbbb +babbaaaaabaaabbbbbaaababaaaaaabaababbbababbabbbbaaabbbba +abbababbbaabbabbabaabbabaaaaabbb +ababaaabbaaaaabbabbbabaabbaabbbaabaaaaabbaabaabbabbbaaaa +babbaaaabaabababbaaaabbb +aaabbbaaaabbbabababaabaa +bbbaaabaababbaabababaaba +aaababbaaabbaababbbbabbabbbabbab +abababbaaababaababbaabba +bbaaabbabbbbababaaaabaab \ No newline at end of file diff --git a/data/advent19a.txt b/data/advent19a.txt new file mode 100644 index 0000000..a76d890 --- /dev/null +++ b/data/advent19a.txt @@ -0,0 +1,12 @@ +0: 4 1 5 +1: 2 3 | 3 2 +2: 4 4 | 5 5 +3: 4 5 | 5 4 +4: "a" +5: "b" + +ababbb +bababa +abbbab +aaabbb +aaaabbb \ No newline at end of file diff --git a/data/advent19b.txt b/data/advent19b.txt new file mode 100644 index 0000000..0962991 --- /dev/null +++ b/data/advent19b.txt @@ -0,0 +1,47 @@ +42: 9 14 | 10 1 +9: 14 27 | 1 26 +10: 23 14 | 28 1 +1: "a" +11: 42 31 +5: 1 14 | 15 1 +19: 14 1 | 14 14 +12: 24 14 | 19 1 +16: 15 1 | 14 14 +31: 14 17 | 1 13 +6: 14 14 | 1 14 +2: 1 24 | 14 4 +0: 8 11 +13: 14 3 | 1 12 +15: 1 | 14 +17: 14 2 | 1 7 +23: 25 1 | 22 14 +28: 16 1 +4: 1 1 +20: 14 14 | 1 15 +3: 5 14 | 16 1 +27: 1 6 | 14 18 +14: "b" +21: 14 1 | 1 14 +25: 1 1 | 1 14 +22: 14 14 +8: 42 +26: 14 22 | 1 20 +18: 15 15 +7: 14 5 | 1 21 +24: 14 1 + +abbbbbabbbaaaababbaabbbbabababbbabbbbbbabaaaa +bbabbbbaabaabba +babbbbaabbbbbabbbbbbaabaaabaaa +aaabbbbbbaaaabaababaabababbabaaabbababababaaa +bbbbbbbaaaabbbbaaabbabaaa +bbbababbbbaaaaaaaabbababaaababaabab +ababaaaaaabaaab +ababaaaaabbbaba +baabbaaaabbaaaababbaababb +abbbbabbbbaaaababbbbbbaaaababb +aaaaabbaabaaaaababaa +aaaabbaaaabbaaa +aaaabbaabbaaaaaaabbbabbbaaabbaabaaa +babaaabbbaaabaababbaabababaaab +aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba \ No newline at end of file diff --git a/data/advent19tiny.txt b/data/advent19tiny.txt new file mode 100644 index 0000000..e5c4bc1 --- /dev/null +++ b/data/advent19tiny.txt @@ -0,0 +1,11 @@ +0: 8 11 +8: 42 | 42 8 +42: "a" +11: 42 31 | 42 11 31 +31: "b" + +ab +aabb +aaa +b +aaab \ No newline at end of file diff --git a/problems/day19.html b/problems/day19.html new file mode 100644 index 0000000..936d811 --- /dev/null +++ b/problems/day19.html @@ -0,0 +1,233 @@ + + + + +Day 19 - Advent of Code 2020 + + + + + + + +

Advent of Code

Neil Smith (AoC++) 38*

 {'year':2020}

+ + + +
+ +

--- Day 19: Monster Messages ---

You land in an airport surrounded by dense forest. As you walk to your high-speed train, the Elves at the Mythical Information Bureau contact you again. They think their satellite has collected an image of a sea monster! Unfortunately, the connection to the satellite is having problems, and many of the messages sent back from the satellite have been corrupted.

+

They sent you a list of the rules valid messages should obey and a list of received messages they've collected so far (your puzzle input).

+

The rules for valid messages (the top part of your puzzle input) are numbered and build upon each other. For example:

+
0: 1 2
+1: "a"
+2: 1 3 | 3 1
+3: "b"
+
+

Some rules, like 3: "b", simply match a single character (in this case, b).

+

The remaining rules list the sub-rules that must be followed; for example, the rule 0: 1 2 means that to match rule 0, the text being checked must match rule 1, and the text after the part that matched rule 1 must then match rule 2.

+

Some of the rules have multiple lists of sub-rules separated by a pipe (|). This means that at least one list of sub-rules must match. (The ones that match might be different each time the rule is encountered.) For example, the rule 2: 1 3 | 3 1 means that to match rule 2, the text being checked must match rule 1 followed by rule 3 or it must match rule 3 followed by rule 1.

+

Fortunately, there are no loops in the rules, so the list of possible matches will be finite. Since rule 1 matches a and rule 3 matches b, rule 2 matches either ab or ba. Therefore, rule 0 matches aab or aba.

+

Here's a more interesting example:

+
0: 4 1 5
+1: 2 3 | 3 2
+2: 4 4 | 5 5
+3: 4 5 | 5 4
+4: "a"
+5: "b"
+
+

Here, because rule 4 matches a and rule 5 matches b, rule 2 matches two letters that are the same (aa or bb), and rule 3 matches two letters that are different (ab or ba).

+

Since rule 1 matches rules 2 and 3 once each in either order, it must match two pairs of letters, one pair with matching letters and one pair with different letters. This leaves eight possibilities: aaab, aaba, bbab, bbba, abaa, abbb, baaa, or babb.

+

Rule 0, therefore, matches a (rule 4), then any of the eight options from rule 1, then b (rule 5): aaaabb, aaabab, abbabb, abbbab, aabaab, aabbbb, abaaab, or ababbb.

+

The received messages (the bottom part of your puzzle input) need to be checked against the rules so you can determine which are valid and which are corrupted. Including the rules and the messages together, this might look like:

+
0: 4 1 5
+1: 2 3 | 3 2
+2: 4 4 | 5 5
+3: 4 5 | 5 4
+4: "a"
+5: "b"
+
+ababbb
+bababa
+abbbab
+aaabbb
+aaaabbb
+
+

Your goal is to determine the number of messages that completely match rule 0. In the above example, ababbb and abbbab match, but bababa, aaabbb, and aaaabbb do not, producing the answer 2. The whole message must match all of rule 0; there can't be extra unmatched characters in the message. (For example, aaaabbb might appear to match rule 0 above, but it has an extra unmatched b on the end.)

+

How many messages completely match rule 0?

+
+

Your puzzle answer was 235.

--- Part Two ---

As you look over the list of messages, you realize your matching rules aren't quite right. To fix them, completely replace rules 8: 42 and 11: 42 31 with the following:

+
8: 42 | 42 8
+11: 42 31 | 42 11 31
+
+

This small change has a big impact: now, the rules do contain loops, and the list of messages they could hypothetically match is infinite. You'll need to determine how these changes affect which messages are valid.

+

Fortunately, many of the rules are unaffected by this change; it might help to start by looking at which rules always match the same set of values and how those rules (especially rules 42 and 31) are used by the new versions of rules 8 and 11.

+

(Remember, you only need to handle the rules you have; building a solution that could handle any hypothetical combination of rules would be significantly more difficult.)

+

For example:

+
42: 9 14 | 10 1
+9: 14 27 | 1 26
+10: 23 14 | 28 1
+1: "a"
+11: 42 31
+5: 1 14 | 15 1
+19: 14 1 | 14 14
+12: 24 14 | 19 1
+16: 15 1 | 14 14
+31: 14 17 | 1 13
+6: 14 14 | 1 14
+2: 1 24 | 14 4
+0: 8 11
+13: 14 3 | 1 12
+15: 1 | 14
+17: 14 2 | 1 7
+23: 25 1 | 22 14
+28: 16 1
+4: 1 1
+20: 14 14 | 1 15
+3: 5 14 | 16 1
+27: 1 6 | 14 18
+14: "b"
+21: 14 1 | 1 14
+25: 1 1 | 1 14
+22: 14 14
+8: 42
+26: 14 22 | 1 20
+18: 15 15
+7: 14 5 | 1 21
+24: 14 1
+
+abbbbbabbbaaaababbaabbbbabababbbabbbbbbabaaaa
+bbabbbbaabaabba
+babbbbaabbbbbabbbbbbaabaaabaaa
+aaabbbbbbaaaabaababaabababbabaaabbababababaaa
+bbbbbbbaaaabbbbaaabbabaaa
+bbbababbbbaaaaaaaabbababaaababaabab
+ababaaaaaabaaab
+ababaaaaabbbaba
+baabbaaaabbaaaababbaababb
+abbbbabbbbaaaababbbbbbaaaababb
+aaaaabbaabaaaaababaa
+aaaabbaaaabbaaa
+aaaabbaabbaaaaaaabbbabbbaaabbaabaaa
+babaaabbbaaabaababbaabababaaab
+aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba
+
+

Without updating rules 8 and 11, these rules only match three messages: bbabbbbaabaabba, ababaaaaaabaaab, and ababaaaaabbbaba.

+

However, after updating rules 8 and 11, a total of 12 messages match:

+
    +
  • bbabbbbaabaabba
  • +
  • babbbbaabbbbbabbbbbbaabaaabaaa
  • +
  • aaabbbbbbaaaabaababaabababbabaaabbababababaaa
  • +
  • bbbbbbbaaaabbbbaaabbabaaa
  • +
  • bbbababbbbaaaaaaaabbababaaababaabab
  • +
  • ababaaaaaabaaab
  • +
  • ababaaaaabbbaba
  • +
  • baabbaaaabbaaaababbaababb
  • +
  • abbbbabbbbaaaababbbbbbaaaababb
  • +
  • aaaaabbaabaaaaababaa
  • +
  • aaaabbaabbaaaaaaabbbabbbaaabbaabaaa
  • +
  • aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba
  • +
+

After updating rules 8 and 11, how many messages completely match rule 0?

+
+

Your puzzle answer was 379.

Both parts of this puzzle are complete! They provide two gold stars: **

+

At this point, you should return to your Advent calendar and try another puzzle.

+

If you still want to see it, you can get your puzzle input.

+

You can also this puzzle.

+
+ + + + + + \ No newline at end of file diff --git a/stack.yaml b/stack.yaml index ba78e95..f6be361 100644 --- a/stack.yaml +++ b/stack.yaml @@ -53,6 +53,7 @@ packages: - advent16 - advent17 - advent18 +- advent19 # Dependency packages to be pulled from upstream that are not in the resolver. # These entries can reference officially published versions as well as