|
1 | 1 | # Answers
|
2 | 2 |
|
3 |
| -| Part 1 | Part 2 | |
4 |
| -| ------ | ------ | |
5 |
| -| ` ` | ` ` | |
| 3 | +| Part 1 | Part 2 | |
| 4 | +| ------ | ------- | |
| 5 | +| `179` | `18925` | |
| 6 | + |
| 7 | +## --- Day 7: Handy Haversacks --- |
| 8 | + |
| 9 | +You land at the regional airport in time for your next flight. In fact, it looks like you'll even have time to grab some food: all flights are currently delayed due to _issues in luggage processing_. |
| 10 | + |
| 11 | +Due to recent aviation regulations, many rules (your puzzle input) are being enforced about bags and their contents; bags must be color-coded and must contain specific quantities of other color-coded bags. Apparently, nobody responsible for these regulations considered how long they would take to enforce! |
| 12 | + |
| 13 | +For example, consider the following rules: |
| 14 | + |
| 15 | + light red bags contain 1 bright white bag, 2 muted yellow bags. |
| 16 | + dark orange bags contain 3 bright white bags, 4 muted yellow bags. |
| 17 | + bright white bags contain 1 shiny gold bag. |
| 18 | + muted yellow bags contain 2 shiny gold bags, 9 faded blue bags. |
| 19 | + shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags. |
| 20 | + dark olive bags contain 3 faded blue bags, 4 dotted black bags. |
| 21 | + vibrant plum bags contain 5 faded blue bags, 6 dotted black bags. |
| 22 | + faded blue bags contain no other bags. |
| 23 | + dotted black bags contain no other bags. |
| 24 | + |
| 25 | + |
| 26 | +These rules specify the required contents for 9 bag types. In this example, every `faded blue` bag is empty, every `vibrant plum` bag contains 11 bags (5 `faded blue` and 6 `dotted black`), and so on. |
| 27 | + |
| 28 | +You have a _`shiny gold`_ bag. If you wanted to carry it in at least one other bag, how many different bag colors would be valid for the outermost bag? (In other words: how many colors can, eventually, contain at least one `shiny gold` bag?) |
| 29 | + |
| 30 | +In the above rules, the following options would be available to you: |
| 31 | + |
| 32 | +* A `bright white` bag, which can hold your `shiny gold` bag directly. |
| 33 | +* A `muted yellow` bag, which can hold your `shiny gold` bag directly, plus some other bags. |
| 34 | +* A `dark orange` bag, which can hold `bright white` and `muted yellow` bags, either of which could then hold your `shiny gold` bag. |
| 35 | +* A `light red` bag, which can hold `bright white` and `muted yellow` bags, either of which could then hold your `shiny gold` bag. |
| 36 | + |
| 37 | +So, in this example, the number of bag colors that can eventually contain at least one `shiny gold` bag is _`4`_. |
| 38 | + |
| 39 | +_How many bag colors can eventually contain at least one `shiny gold` bag?_ (The list of rules is quite long; make sure you get all of it.) |
| 40 | + |
| 41 | +----------------- |
| 42 | + |
| 43 | +## --- Part Two --- |
| 44 | + |
| 45 | +It's getting pretty expensive to fly these days - not because of ticket prices, but because of the ridiculous number of bags you need to buy! |
| 46 | + |
| 47 | +Consider again your `shiny gold` bag and the rules from the above example: |
| 48 | + |
| 49 | +* `faded blue` bags contain `0` other bags. |
| 50 | +* `dotted black` bags contain `0` other bags. |
| 51 | +* `vibrant plum` bags contain `11` other bags: 5 `faded blue` bags and 6 `dotted black` bags. |
| 52 | +* `dark olive` bags contain `7` other bags: 3 `faded blue` bags and 4 `dotted black` bags. |
| 53 | + |
| 54 | +So, a single `shiny gold` bag must contain 1 `dark olive` bag (and the 7 bags within it) plus 2 `vibrant plum` bags (and the 11 bags within _each_ of those): `1 + 1*7 + 2 + 2*11` = _`32`_ bags! |
| 55 | + |
| 56 | +Of course, the actual rules have a small chance of going several levels deeper than this example; be sure to count all of the bags, even if the nesting becomes topologically impractical! |
| 57 | + |
| 58 | +Here's another example: |
| 59 | + |
| 60 | + shiny gold bags contain 2 dark red bags. |
| 61 | + dark red bags contain 2 dark orange bags. |
| 62 | + dark orange bags contain 2 dark yellow bags. |
| 63 | + dark yellow bags contain 2 dark green bags. |
| 64 | + dark green bags contain 2 dark blue bags. |
| 65 | + dark blue bags contain 2 dark violet bags. |
| 66 | + dark violet bags contain no other bags. |
| 67 | + |
| 68 | + |
| 69 | +In this example, a single `shiny gold` bag must contain _`126`_ other bags. |
| 70 | + |
| 71 | +_How many individual bags are required inside your single `shiny gold` bag?_ |
0 commit comments