-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solve Day 19 #32
Merged
Merged
Solve Day 19 #32
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report
@@ Coverage Diff @@
## main #32 +/- ##
==========================================
- Coverage 94.21% 93.67% -0.54%
==========================================
Files 31 32 +1
Lines 622 664 +42
Branches 47 47
==========================================
+ Hits 586 622 +36
- Misses 21 27 +6
Partials 15 15
Continue to review full report at Codecov.
|
manuphatak
added a commit
that referenced
this pull request
Jan 17, 2021
* origin/main: Solve Day 19 (#32)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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 rule0
, the text being checked must match rule1
, and the text after the part that matched rule1
must then match rule2
.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 rule2: 1 3 | 3 1
means that to match rule2
, the text being checked must match rule1
followed by rule3
or it must match rule3
followed by rule1
.Fortunately, there are no loops in the rules, so the list of possible matches will be finite. Since rule
1
matchesa
and rule3
matchesb
, rule2
matches eitherab
orba
. Therefore, rule0
matchesaab
oraba
.Here's a more interesting example:
Here, because rule
4
matchesa
and rule5
matchesb
, rule2
matches two letters that are the same (aa
orbb
), and rule3
matches two letters that are different (ab
orba
).Since rule
1
matches rules2
and3
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
, orbabb
.Rule
0
, therefore, matchesa
(rule4
), then any of the eight options from rule1
, thenb
(rule5
):aaaabb
,aaabab
,abbabb
,abbbab
,aabaab
,aabbbb
,abaaab
, orababbb
.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:
Your goal is to determine the number of messages that completely match rule
0
. In the above example,ababbb
andabbbab
match, butbababa
,aaabbb
, andaaaabbb
do not, producing the answer2
. The whole message must match all of rule0
; there can't be extra unmatched characters in the message. (For example,aaaabbb
might appear to match rule0
above, but it has an extra unmatchedb
on the end.)How many messages completely match rule
0
?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
and11: 42 31
with the following: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
and31
) are used by the new versions of rules8
and11
.(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:
Without updating rules
8
and11
, these rules only match three messages:bbabbbbaabaabba
,ababaaaaaabaaab
, andababaaaaabbbaba
.However, after updating rules
8
and11
, a total of12
messages match:bbabbbbaabaabba
babbbbaabbbbbabbbbbbaabaaabaaa
aaabbbbbbaaaabaababaabababbabaaabbababababaaa
bbbbbbbaaaabbbbaaabbabaaa
bbbababbbbaaaaaaaabbababaaababaabab
ababaaaaaabaaab
ababaaaaabbbaba
baabbaaaabbaaaababbaababb
abbbbabbbbaaaababbbbbbaaaababb
aaaaabbaabaaaaababaa
aaaabbaabbaaaaaaabbbabbbaaabbaabaaa
aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba
After updating rules
8
and11
, how many messages completely match rule0
?Link
https://adventofcode.com/2020/day/19