Day 14
[advent-of-code-2021.git] / day14 / task.txt
1 --- Day 14: Extended Polymerization ---
2 The incredible pressures at this depth are starting to put a strain on your submarine. The submarine has polymerization equipment that would produce suitable materials to reinforce the submarine, and the nearby volcanically-active caves should even have the necessary input elements in sufficient quantities.
3
4 The submarine manual contains instructions for finding the optimal polymer formula; specifically, it offers a polymer template and a list of pair insertion rules (your puzzle input). You just need to work out what polymer would result after repeating the pair insertion process a few times.
5
6 For example:
7
8 NNCB
9
10 CH -> B
11 HH -> N
12 CB -> H
13 NH -> C
14 HB -> C
15 HC -> B
16 HN -> C
17 NN -> C
18 BH -> H
19 NC -> B
20 NB -> B
21 BN -> B
22 BB -> N
23 BC -> B
24 CC -> N
25 CN -> C
26 The first line is the polymer template - this is the starting point of the process.
27
28 The following section defines the pair insertion rules. A rule like AB -> C means that when elements A and B are immediately adjacent, element C should be inserted between them. These insertions all happen simultaneously.
29
30 So, starting with the polymer template NNCB, the first step simultaneously considers all three pairs:
31
32 The first pair (NN) matches the rule NN -> C, so element C is inserted between the first N and the second N.
33 The second pair (NC) matches the rule NC -> B, so element B is inserted between the N and the C.
34 The third pair (CB) matches the rule CB -> H, so element H is inserted between the C and the B.
35 Note that these pairs overlap: the second element of one pair is the first element of the next pair. Also, because all pairs are considered simultaneously, inserted elements are not considered to be part of a pair until the next step.
36
37 After the first step of this process, the polymer becomes NCNBCHB.
38
39 Here are the results of a few steps using the above rules:
40
41 Template:     NNCB
42 After step 1: NCNBCHB
43 After step 2: NBCCNBBBCBHCB
44 After step 3: NBBBCNCCNBBNBNBBCHBHHBCHB
45 After step 4: NBBNBNBBCCNBCNCCNBBNBBNBBBNBBNBBCBHCBHHNHCBBCBHCB
46 This polymer grows quickly. After step 5, it has length 97; After step 10, it has length 3073. After step 10, B occurs 1749 times, C occurs 298 times, H occurs 161 times, and N occurs 865 times; taking the quantity of the most common element (B, 1749) and subtracting the quantity of the least common element (H, 161) produces 1749 - 161 = 1588.
47
48 Apply 10 steps of pair insertion to the polymer template and find the most and least common elements in the result. What do you get if you take the quantity of the most common element and subtract the quantity of the least common element?
49
50 Your puzzle answer was 2899.
51
52 --- Part Two ---
53 The resulting polymer isn't nearly strong enough to reinforce the submarine. You'll need to run more steps of the pair insertion process; a total of 40 steps should do it.
54
55 In the above example, the most common element is B (occurring 2192039569602 times) and the least common element is H (occurring 3849876073 times); subtracting these produces 2188189693529.
56
57 Apply 40 steps of pair insertion to the polymer template and find the most and least common elements in the result. What do you get if you take the quantity of the most common element and subtract the quantity of the least common element?
58
59 Your puzzle answer was 3528317079545.
60
61 Both parts of this puzzle are complete! They provide two gold stars: **
62
63 At this point, you should return to your Advent calendar and try another puzzle.
64
65 If you still want to see it, you can get your puzzle input.
66
67 You can also [Share] this puzzle.