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 (2635B)


      1--- Part Two ---
      2
      3To completely determine whether you have enough adapters, you'll need to figure out how many
      4different ways they can be arranged. Every arrangement needs to connect the charging outlet to your
      5device. The previous rules about when adapters can successfully connect still apply.
      6
      7The first example above (the one that starts with 16, 10, 15) supports the following arrangements:
      8
      9(0), 1, 4, 5, 6, 7, 10, 11, 12, 15, 16, 19, (22)
     10(0), 1, 4, 5, 6, 7, 10, 12, 15, 16, 19, (22)
     11(0), 1, 4, 5, 7, 10, 11, 12, 15, 16, 19, (22)
     12(0), 1, 4, 5, 7, 10, 12, 15, 16, 19, (22)
     13(0), 1, 4, 6, 7, 10, 11, 12, 15, 16, 19, (22)
     14(0), 1, 4, 6, 7, 10, 12, 15, 16, 19, (22)
     15(0), 1, 4, 7, 10, 11, 12, 15, 16, 19, (22)
     16(0), 1, 4, 7, 10, 12, 15, 16, 19, (22)
     17
     18(The charging outlet and your device's built-in adapter are shown in parentheses.) Given the
     19adapters from the first example, the total number of arrangements that connect the charging outlet
     20to your device is 8.
     21
     22The second example above (the one that starts with 28, 33, 18) has many arrangements. Here are a
     23few:
     24
     25(0), 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 17, 18, 19, 20, 23, 24, 25, 28, 31,
     2632, 33, 34, 35, 38, 39, 42, 45, 46, 47, 48, 49, (52)
     27
     28(0), 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 17, 18, 19, 20, 23, 24, 25, 28, 31,
     2932, 33, 34, 35, 38, 39, 42, 45, 46, 47, 49, (52)
     30
     31(0), 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 17, 18, 19, 20, 23, 24, 25, 28, 31,
     3232, 33, 34, 35, 38, 39, 42, 45, 46, 48, 49, (52)
     33
     34(0), 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 17, 18, 19, 20, 23, 24, 25, 28, 31,
     3532, 33, 34, 35, 38, 39, 42, 45, 46, 49, (52)
     36
     37(0), 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 17, 18, 19, 20, 23, 24, 25, 28, 31,
     3832, 33, 34, 35, 38, 39, 42, 45, 47, 48, 49, (52)
     39
     40(0), 3, 4, 7, 10, 11, 14, 17, 20, 23, 25, 28, 31, 34, 35, 38, 39, 42, 45,
     4146, 48, 49, (52)
     42
     43(0), 3, 4, 7, 10, 11, 14, 17, 20, 23, 25, 28, 31, 34, 35, 38, 39, 42, 45,
     4446, 49, (52)
     45
     46(0), 3, 4, 7, 10, 11, 14, 17, 20, 23, 25, 28, 31, 34, 35, 38, 39, 42, 45,
     4747, 48, 49, (52)
     48
     49(0), 3, 4, 7, 10, 11, 14, 17, 20, 23, 25, 28, 31, 34, 35, 38, 39, 42, 45,
     5047, 49, (52)
     51
     52(0), 3, 4, 7, 10, 11, 14, 17, 20, 23, 25, 28, 31, 34, 35, 38, 39, 42, 45,
     5348, 49, (52)
     54
     55In total, this set of adapters can connect the charging outlet to your device in 19208
     56distinct arrangements.
     57
     58You glance back down at your bag and try to remember why you brought so many adapters; there must be
     59more than a trillion valid ways to arrange them! Surely, there must be an efficient way
     60to count the arrangements.
     61
     62What is the total number of distinct ways you can arrange the adapters to connect the
     63charging outlet to your device?
     64
     65