-
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 09 #15
Merged
Merged
Solve Day 09 #15
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 #15 +/- ##
==========================================
- Coverage 95.89% 95.06% -0.83%
==========================================
Files 12 14 +2
Lines 146 162 +16
Branches 9 13 +4
==========================================
+ Hits 140 154 +14
- Misses 3 4 +1
- Partials 3 4 +1
Continue to review full report at Codecov.
|
* day_09_repo_improvements: Fix Pedantic warnings from day 8 fix the bin/day command to push to the correct branch Move pedantic check back to test Update hlint.yaml
…ay_09 * origin/day_09_repo_improvements: fix lint warning create pull request with cooler defaults
* origin/main: Fix lint checks and type checks on CI (#16)
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 9: Encoding Error
With your neighbor happily enjoying their video game, you turn your attention to an open data port on the little screen in the seat in front of you.
Though the port is non-standard, you manage to connect it to your computer through the clever use of several paperclips. Upon connection, the port outputs a series of numbers (your puzzle input).
The data appears to be encrypted with the eXchange-Masking Addition System ( XMAS ) which, conveniently for you, is an old cypher with an important weakness.
XMAS starts by transmitting a preamble of 25 numbers. After that, each number you receive should be the sum of any two of the 25 immediately previous numbers. The two numbers will have different values, and there might be more than one such pair.
For example, suppose your preamble consists of the numbers
1
through25
in a random order. To be valid, the next number must be the sum of two of those numbers:26
would be a valid next number, as it could be1
plus25
(or many other pairs, like2
and24
).49
would be a valid next number, as it is the sum of24
and25
.100
would not be valid; no two of the previous 25 numbers sum to100
.50
would also not be valid; although25
appears in the previous 25 numbers, the two numbers in the pair must be different.Suppose the 26th number is
45
, and the first number (no longer an option, as it is more than 25 numbers ago) was20
. Now, for the next number to be valid, there needs to be some pair of numbers among1
-19
,21
-25
, or45
that add up to it:26
would still be a valid next number, as1
and25
are still within the previous 25 numbers.65
would not be valid, as no two of the available numbers sum to it.64
and66
would both be valid , as they are the result of19+45
and21+45
respectively.Here is a larger example which only considers the previous 5 numbers (and has a preamble of length 5):
In this example, after the 5-number preamble, almost every number is the sum of two of the previous 5 numbers; the only number that does not follow this rule is
127
.The first step of attacking the weakness in the XMAS data is to find the first number in the list (after the preamble) which is not the sum of two of the 25 numbers before it. What is the first number that does not have this property?
Part Two
The final step in breaking the XMAS encryption relies on the invalid number you just found: you must find a contiguous set of at least two numbers in your list which sum to the invalid number from step 1.
Again consider the above example:
In this list, adding up all of the numbers from
15
through40
produces the invalid number from step 1,127
. (Of course, the contiguous set of numbers in your actual list might be much longer.)To find the encryption weakness , add together the smallest and largest number in this contiguous range; in this example, these are
15
and47
, producing62
.What is the encryption weakness in your XMAS-encrypted list of numbers?
Link
https://adventofcode.com/2020/day/9