aoc-2020-zig

Advent of Code 2020 Solutions in Zig
git clone https://git.sinitax.com/sinitax/aoc-2020-zig
Log | Files | Refs | README | sfeed.txt

part2 (1377B)


      1--- Part Two ---
      2
      3It's getting pretty expensive to fly these days - not because of ticket prices, but because of the
      4ridiculous number of bags you need to buy!
      5
      6Consider again your shiny gold bag and the rules from the above example:
      7
      8- faded blue bags contain 0 other bags. - dotted black bags contain 0 other bags. - vibrant plum
      9bags contain 11 other bags: 5 faded blue bags and 6 dotted black bags. - dark olive bags contain 7
     10other bags: 3 faded blue bags and 4 dotted black bags.
     11
     12So, a single shiny gold bag must contain 1 dark olive bag (and the 7 bags within it) plus 2 vibrant
     13plum bags (and the 11 bags within each of those): 1 + 1*7 + 2 + 2*11 = 32
     14bags!
     15
     16Of course, the actual rules have a small chance of going several levels deeper than this example; be
     17sure to count all of the bags, even if the nesting becomes topologically impractical!
     18
     19Here's another example:
     20
     21shiny gold bags contain 2 dark red bags. dark red bags contain 2 dark orange bags. dark orange bags
     22contain 2 dark yellow bags. dark yellow bags contain 2 dark green bags. dark green bags contain 2
     23dark blue bags. dark blue bags contain 2 dark violet bags. dark violet bags contain no other bags.
     24
     25In this example, a single shiny gold bag must contain 126 other bags.
     26
     27How many individual bags are required inside your single shiny gold bag?
     28
     29