-
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 10 #18
Merged
Merged
Solve Day 10 #18
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 #18 +/- ##
==========================================
- Coverage 95.51% 94.82% -0.69%
==========================================
Files 26 27 +1
Lines 401 425 +24
Branches 28 28
==========================================
+ Hits 383 403 +20
- Misses 10 14 +4
Partials 8 8
Continue to review full report at Codecov.
|
manuphatak
commented
Dec 21, 2020
manuphatak
added a commit
that referenced
this pull request
Jan 1, 2021
manuphatak
added a commit
that referenced
this pull request
Jan 10, 2021
* origin/main: Update dependencies (#41) Remove hspec skip rules from hlint (#39) Add hlint rule (#37) Solve Day 21 (#35) Refactor: Use LANGUAGE TypeApplications (#36) Solve Day 12 (#21) Solve Day 20 (#34) Solve Day 10 (#18) Harvest parseInts util (#33) Solve Day 18 (#31) Solve Day 17 (#30) Create Advent.Parser for shared parsers (#29) Solve Day 16 (#26) Add hspec-discover to PATH (#28)
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 10: Adapter Array
Patched into the aircraft's data port, you discover weather forecasts of a massive tropical storm. Before you can figure out whether it will impact your vacation plans, however, your device suddenly turns off!
Its battery is dead.
You'll need to plug it in. There's only one problem: the charging outlet near your seat produces the wrong number of jolts . Always prepared, you make a list of all of the joltage adapters in your bag.
Each of your joltage adapters is rated for a specific output joltage (your puzzle input). Any given adapter can take an input
1
,2
, or3
jolts lower than its rating and still produce its rated output joltage.In addition, your device has a built-in joltage adapter rated for
3
jolts higher than the highest-rated adapter in your bag. (If your adapter list were3
,9
, and6
, your device's built-in adapter would be rated for12
jolts.)Treat the charging outlet near your seat as having an effective joltage rating of
0
.Since you have some time to kill, you might as well test all of your adapters. Wouldn't want to get to your resort and realize you can't even charge your device!
If you use every adapter in your bag at once, what is the distribution of joltage differences between the charging outlet, the adapters, and your device?
For example, suppose that in your bag, you have adapters with the following joltage ratings:
With these adapters, your device's built-in joltage adapter would be rated for
19 + 3 = _22_
jolts, 3 higher than the highest-rated adapter.Because adapters can only connect to a source 1-3 jolts lower than its rating, in order to use every adapter, you'd need to choose them like this:
0
jolts, so the only adapters that could connect to it directly would need to have a joltage rating of1
,2
, or3
jolts. Of these, only one you have is an adapter rated1
jolt (difference of1
).1
-jolt rated adapter, the only choice is your4
-jolt rated adapter (difference of3
).4
-jolt rated adapter, the adapters rated5
,6
, or7
are valid choices. However, in order to not skip any adapters, you have to pick the adapter rated5
jolts (difference of1
).6
and then the adapter rated7
(with difference of1
and1
).7
-jolt rated adapter is the one rated10
jolts (difference of3
).10
, the choices are11
or12
; choose11
(difference of1
) and then12
(difference of1
).12
, only valid adapter has a rating of15
(difference of3
), then16
(difference of1
), then19
(difference of3
).22
jolts (always a difference of3
).In this example, when using every adapter, there are
7
differences of 1 jolt and5
differences of 3 jolts.Here is a larger example:
In this larger example, in a chain that uses all of the adapters, there are
22
differences of 1 jolt and10
differences of 3 jolts.Find a chain that uses all of your adapters to connect the charging outlet to your device's built-in adapter and count the joltage differences between the charging outlet, the adapters, and your device. What is the number of 1-jolt differences multiplied by the number of 3-jolt differences?
Part Two
To completely determine whether you have enough adapters, you'll need to figure out how many different ways they can be arranged. Every arrangement needs to connect the charging outlet to your device. The previous rules about when adapters can successfully connect still apply.
The first example above (the one that starts with
16
,10
,15
) supports the following arrangements:(The charging outlet and your device's built-in adapter are shown in parentheses.) Given the adapters from the first example, the total number of arrangements that connect the charging outlet to your device is
8
.The second example above (the one that starts with
28
,33
,18
) has many arrangements. Here are a few:In total, this set of adapters can connect the charging outlet to your device in
19208
distinct arrangements.You glance back down at your bag and try to remember why you brought so many adapters; there must be more than a trillion valid ways to arrange them! Surely, there must be an efficient way to count the arrangements.
What is the total number of distinct ways you can arrange the adapters to connect the charging outlet to your device?
Link
https://adventofcode.com/2020/day/10