-
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 21 #35
Merged
Merged
Solve Day 21 #35
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 #35 +/- ##
==========================================
+ Coverage 94.68% 94.77% +0.08%
==========================================
Files 29 30 +1
Lines 546 574 +28
Branches 34 34
==========================================
+ Hits 517 544 +27
- Misses 18 19 +1
Partials 11 11
Continue to review full report at Codecov.
|
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 21: Allergen Assessment
You reach the train's last stop and the closest you can get to your vacation island without getting wet. There aren't even any boats here, but nothing can stop you now: you build a raft. You just need a few days' worth of food for your journey.
You don't speak the local language, so you can't read any ingredients lists. However, sometimes, allergens are listed in a language you do understand. You should be able to use this information to determine which ingredient contains which allergen and work out which foods are safe to take with you on your trip.
You start by compiling a list of foods (your puzzle input), one food per line. Each line includes that food's ingredients list followed by some or all of the allergens the food contains.
Each allergen is found in exactly one ingredient. Each ingredient contains zero or one allergen. Allergens aren't always marked ; when they're listed (as in
(contains nuts, shellfish)
after an ingredients list), the ingredient that contains each listed allergen will be somewhere in the corresponding ingredients list . However, even if an allergen isn't listed, the ingredient that contains that allergen could still be present: maybe they forgot to label it, or maybe it was labeled in a language you don't know.For example, consider the following list of foods:
The first food in the list has four ingredients (written in a language you don't understand):
mxmxvkd
,kfcds
,sqjhc
, andnhms
. While the food might contain other allergens, a few allergens the food definitely contains are listed afterward:dairy
andfish
.The first step is to determine which ingredients can't possibly contain any of the allergens in any food in your list. In the above example, none of the ingredients
kfcds
,nhms
,sbzzf
, ortrh
can contain an allergen. Counting the number of times any of these ingredients appear in any ingredients list produces5
: they all appear once each exceptsbzzf
, which appears twice.Determine which ingredients cannot possibly contain any of the allergens in your list. How many times do any of those ingredients appear?
Part Two
Now that you've isolated the inert ingredients, you should have enough information to figure out which ingredient contains which allergen.
In the above example:
mxmxvkd
containsdairy
.sqjhc
containsfish
.fvjkl
containssoy
.Arrange the ingredients alphabetically by their allergen and separate them by commas to produce your canonical dangerous ingredient list . (There should not be any spaces in your canonical dangerous ingredient list.) In the above example, this would be
mxmxvkd,sqjhc,fvjkl
.Time to stock your raft with supplies. What is your canonical dangerous ingredient list?
Link
https://adventofcode.com/2020/day/21