diff options
author | kaiwu <kaiwu2004@gmail.com> | 2022-05-06 17:00:56 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2022-05-06 17:00:56 +0800 |
commit | 489e00a212d906bff2d61213f3182e6618367d7f (patch) | |
tree | 03a9ffcbdc3313db1e92fa14490625671b3da67d /src | |
parent | 79a25bdb20f0a9fb958f1edcd6fa525a1a3cfd62 (diff) | |
download | advent-of-code-489e00a212d906bff2d61213f3182e6618367d7f.tar.gz advent-of-code-489e00a212d906bff2d61213f3182e6618367d7f.zip |
day7
Diffstat (limited to 'src')
-rw-r--r-- | src/2020/day7/README.md | 25 | ||||
-rw-r--r-- | src/2021/day7/README.md | 20 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/2020/day7/README.md b/src/2020/day7/README.md index fcb2981..d1fcda6 100644 --- a/src/2020/day7/README.md +++ b/src/2020/day7/README.md @@ -28,3 +28,28 @@ So, in this example, the number of bag colors that can eventually contain at lea 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.) +--- Part Two --- +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! + +Consider again your shiny gold bag and the rules from the above example: + +faded blue bags contain 0 other bags. +dotted black bags contain 0 other bags. +vibrant plum bags contain 11 other bags: 5 faded blue bags and 6 dotted black bags. +dark olive bags contain 7 other bags: 3 faded blue bags and 4 dotted black bags. +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! + +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! + +Here's another example: + +shiny gold bags contain 2 dark red bags. +dark red bags contain 2 dark orange bags. +dark orange bags contain 2 dark yellow bags. +dark yellow bags contain 2 dark green bags. +dark green bags contain 2 dark blue bags. +dark blue bags contain 2 dark violet bags. +dark violet bags contain no other bags. +In this example, a single shiny gold bag must contain 126 other bags. + +How many individual bags are required inside your single shiny gold bag? diff --git a/src/2021/day7/README.md b/src/2021/day7/README.md index a451634..717cae8 100644 --- a/src/2021/day7/README.md +++ b/src/2021/day7/README.md @@ -30,3 +30,23 @@ This costs a total of 37 fuel. This is the cheapest possible outcome; more expen Determine the horizontal position that the crabs can align to using the least fuel possible. How much fuel must they spend to align to that position? +--- Part Two --- +The crabs don't seem interested in your proposed solution. Perhaps you misunderstand crab engineering? + +As it turns out, crab submarine engines don't burn fuel at a constant rate. Instead, each change of 1 step in horizontal position costs 1 more unit of fuel than the last: the first step costs 1, the second step costs 2, the third step costs 3, and so on. + +As each crab moves, moving further becomes more expensive. This changes the best horizontal position to align them all on; in the example above, this becomes 5: + +Move from 16 to 5: 66 fuel +Move from 1 to 5: 10 fuel +Move from 2 to 5: 6 fuel +Move from 0 to 5: 15 fuel +Move from 4 to 5: 1 fuel +Move from 2 to 5: 6 fuel +Move from 7 to 5: 3 fuel +Move from 1 to 5: 10 fuel +Move from 2 to 5: 6 fuel +Move from 14 to 5: 45 fuel +This costs a total of 168 fuel. This is the new cheapest possible outcome; the old alignment position (2) now costs 206 fuel instead. + +Determine the horizontal position that the crabs can align to using the least fuel possible so they can make you an escape route! How much fuel must they spend to align to that position? |